@Override
    public ObjectNode encode(ForwardingObjective forwardingObjective, CodecContext context) {

        checkNotNull(forwardingObjective, 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(forwardingObjective, context);

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

        // encode flag
        result.put(FLAG, forwardingObjective.flag().toString());

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

        // encode selector
        ObjectNode trafficSelectorNode =
                trafficSelectorCodec.encode(forwardingObjective.selector(), context);
        result.set(SELECTOR, trafficSelectorNode);

        // encode nextId
        if (forwardingObjective.nextId() != null) {
            result.put(NEXT_ID, forwardingObjective.nextId());
        }

        // encode treatment
        if (forwardingObjective.treatment() != null) {
            ObjectNode trafficTreatmentNode =
                    trafficTreatmentCodec.encode(forwardingObjective.treatment(), context);
            result.set(TREATMENT, trafficTreatmentNode);
        }

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

        Criterion criterion1 = Criteria.matchVlanId(VlanId.ANY);
        Criterion criterion2 = Criteria.matchEthType((short) 0x8844);
        TrafficSelector selector = DefaultTrafficSelector.builder()
                .add(criterion1)
                .add(criterion2)
                .build();

        ForwardingObjective forwardingObj = DefaultForwardingObjective.builder()
                .makePermanent()
                .fromApp(APP_ID)
                .withPriority(60)
                .withFlag(ForwardingObjective.Flag.SPECIFIC)
                .nextStep(1)
                .withSelector(selector)
                .add();

        ObjectNode forwardingObjJson = forwardingObjectiveCodec.encode(forwardingObj, context);
        assertThat(forwardingObjJson, matchesForwardingObjective(forwardingObj));
    }