@Override
    public ObjectNode encode(TrafficSelector selector, CodecContext context) {
        checkNotNull(selector, "Traffic selector cannot be null");

        final ObjectNode result = context.mapper().createObjectNode();
        final ArrayNode jsonCriteria = result.putArray(CRITERIA);

        if (selector.criteria() != null) {
            final JsonCodec<Criterion> criterionCodec =
                    context.codec(Criterion.class);
            for (final Criterion criterion : selector.criteria()) {
                jsonCriteria.add(criterionCodec.encode(criterion, context));
            }
        }

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

        Criterion inPort = Criteria.matchInPort(PortNumber.portNumber(0));
        Criterion ethSrc = Criteria.matchEthSrc(MacAddress.valueOf("11:22:33:44:55:66"));
        Criterion ethDst = Criteria.matchEthDst(MacAddress.valueOf("44:55:66:77:88:99"));
        Criterion ethType = Criteria.matchEthType(Ethernet.TYPE_IPV4);

        TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
        TrafficSelector selector = sBuilder
                .add(inPort)
                .add(ethSrc)
                .add(ethDst)
                .add(ethType)
                .build();

        ObjectNode selectorJson = trafficSelectorCodec.encode(selector, context);
        assertThat(selectorJson, TrafficSelectorJsonMatcher.matchesTrafficSelector(selector));
    }