@Override
    public ObjectNode encode(NextObjective nextObjective, CodecContext context) {

        checkNotNull(nextObjective, NOT_NULL_MESSAGE);

        final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class);
        final JsonCodec<TrafficSelector> trafficSelectorCodec = context.codec(TrafficSelector.class);

        // encode common properties
        ObjectiveCodecHelper och = new ObjectiveCodecHelper();
        ObjectNode result = och.encode(nextObjective, context);

        // encode id
        result.put(ID, nextObjective.id());

        // encode type
        result.put(TYPE, nextObjective.type().toString());

        // encode operation
        result.put(OPERATION, nextObjective.op().toString());

        // encode treatments
        ArrayNode treatments = context.mapper().createArrayNode();
        nextObjective.nextTreatments().forEach(nt -> {
            if (nt.type().equals(NextTreatment.Type.TREATMENT)) {
                TrafficTreatment tt = ((DefaultNextTreatment) nt).treatment();
                ObjectNode treatmentJson = trafficTreatmentCodec.encode(tt, context);
                treatmentJson.put(WEIGHT, nt.weight());
                treatments.add(treatmentJson);
            }
        });
        result.set(TREATMENTS, treatments);

        // encode meta
        if (nextObjective.meta() != null) {
            ObjectNode trafficSelectorNode = trafficSelectorCodec.encode(nextObjective.meta(), context);
            result.set(META, trafficSelectorNode);
        }

        return result;
    }
@Test
    public void testNextObjectiveEncode() {

        TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
        NextTreatment nextTreatment = DefaultNextTreatment.of(treatment, 5);

        NextObjective nextObj = DefaultNextObjective.builder()
                .makePermanent()
                .withType(NextObjective.Type.HASHED)
                .fromApp(APP_ID)
                .withPriority(60)
                .withId(5)
                .addTreatment(nextTreatment)
                .add();

        ObjectNode nextObjJson = nextObjectiveCodec.encode(nextObj, context);
        assertThat(nextObjJson, matchesNextObjective(nextObj));
    }