class TrafficSelectorCodec extends JsonCodec<TrafficSelector> {

    @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;
    }

}