@Test public void testFilteringObjectiveEncode() { Criterion condition1 = Criteria.matchVlanId(VlanId.ANY); Criterion condition2 = Criteria.matchEthType((short) 0x8844); FilteringObjective filteringObj = DefaultFilteringObjective.builder() .makePermanent() .permit() .fromApp(APP_ID) .withPriority(60) .addCondition(condition1) .addCondition(condition2) .add(); ObjectNode filteringObjJson = filteringObjectiveCodec.encode(filteringObj, context); assertThat(filteringObjJson, matchesFilteringObjective(filteringObj)); }
@Override public ObjectNode encode(FilteringObjective filteringObjective, CodecContext context) { checkNotNull(filteringObjective, NOT_NULL_MESSAGE); final JsonCodec<Criterion> criterionCodec = context.codec(Criterion.class); final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class); ObjectiveCodecHelper och = new ObjectiveCodecHelper(); ObjectNode result = och.encode(filteringObjective, context); result.put(ID, filteringObjective.id()); result.put(TYPE, filteringObjective.type().toString()); if (filteringObjective.key() != null) { ObjectNode criterionNode = criterionCodec.encode(filteringObjective.key(), context); result.set(KEY, criterionNode); } if (filteringObjective.meta() != null) { ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(filteringObjective.meta(), context); result.set(META, trafficTreatmentNode); } ArrayNode conditions = context.mapper().createArrayNode(); filteringObjective.conditions().forEach(c -> { ObjectNode criterionJson = criterionCodec.encode(c, context); conditions.add(criterionJson); }); result.set(CONDITIONS, conditions); return result; }
FilteringObjectiveCodec extends JsonCodec<FilteringObjective> { @Override public ObjectNode encode(FilteringObjective filteringObjective, CodecContext context) { checkNotNull(filteringObjective, NOT_NULL_MESSAGE); final JsonCodec<Criterion> criterionCodec = context.codec(Criterion.class); final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class); ObjectiveCodecHelper och = new ObjectiveCodecHelper(); ObjectNode result = och.encode(filteringObjective, context); result.put(ID, filteringObjective.id()); result.put(TYPE, filteringObjective.type().toString()); if (filteringObjective.key() != null) { ObjectNode criterionNode = criterionCodec.encode(filteringObjective.key(), context); result.set(KEY, criterionNode); } if (filteringObjective.meta() != null) { ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(filteringObjective.meta(), context); result.set(META, trafficTreatmentNode); } ArrayNode conditions = context.mapper().createArrayNode(); filteringObjective.conditions().forEach(c -> { ObjectNode criterionJson = criterionCodec.encode(c, context); conditions.add(criterionJson); }); result.set(CONDITIONS, conditions); return result; } }
FilteringObjectiveCodec extends JsonCodec<FilteringObjective> { @Override public ObjectNode encode(FilteringObjective filteringObjective, CodecContext context) { checkNotNull(filteringObjective, NOT_NULL_MESSAGE); final JsonCodec<Criterion> criterionCodec = context.codec(Criterion.class); final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class); ObjectiveCodecHelper och = new ObjectiveCodecHelper(); ObjectNode result = och.encode(filteringObjective, context); result.put(ID, filteringObjective.id()); result.put(TYPE, filteringObjective.type().toString()); if (filteringObjective.key() != null) { ObjectNode criterionNode = criterionCodec.encode(filteringObjective.key(), context); result.set(KEY, criterionNode); } if (filteringObjective.meta() != null) { ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(filteringObjective.meta(), context); result.set(META, trafficTreatmentNode); } ArrayNode conditions = context.mapper().createArrayNode(); filteringObjective.conditions().forEach(c -> { ObjectNode criterionJson = criterionCodec.encode(c, context); conditions.add(criterionJson); }); result.set(CONDITIONS, conditions); return result; }  }
FilteringObjectiveCodec extends JsonCodec<FilteringObjective> { @Override public ObjectNode encode(FilteringObjective filteringObjective, CodecContext context) { checkNotNull(filteringObjective, NOT_NULL_MESSAGE); final JsonCodec<Criterion> criterionCodec = context.codec(Criterion.class); final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class); ObjectiveCodecHelper och = new ObjectiveCodecHelper(); ObjectNode result = och.encode(filteringObjective, context); result.put(ID, filteringObjective.id()); result.put(TYPE, filteringObjective.type().toString()); if (filteringObjective.key() != null) { ObjectNode criterionNode = criterionCodec.encode(filteringObjective.key(), context); result.set(KEY, criterionNode); } if (filteringObjective.meta() != null) { ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(filteringObjective.meta(), context); result.set(META, trafficTreatmentNode); } ArrayNode conditions = context.mapper().createArrayNode(); filteringObjective.conditions().forEach(c -> { ObjectNode criterionJson = criterionCodec.encode(c, context); conditions.add(criterionJson); }); result.set(CONDITIONS, conditions); return result; }  @Override ObjectNode encode(FilteringObjective filteringObjective, CodecContext context); @Override FilteringObjective decode(ObjectNode json, CodecContext context); }
FilteringObjectiveCodec extends JsonCodec<FilteringObjective> { @Override public ObjectNode encode(FilteringObjective filteringObjective, CodecContext context) { checkNotNull(filteringObjective, NOT_NULL_MESSAGE); final JsonCodec<Criterion> criterionCodec = context.codec(Criterion.class); final JsonCodec<TrafficTreatment> trafficTreatmentCodec = context.codec(TrafficTreatment.class); ObjectiveCodecHelper och = new ObjectiveCodecHelper(); ObjectNode result = och.encode(filteringObjective, context); result.put(ID, filteringObjective.id()); result.put(TYPE, filteringObjective.type().toString()); if (filteringObjective.key() != null) { ObjectNode criterionNode = criterionCodec.encode(filteringObjective.key(), context); result.set(KEY, criterionNode); } if (filteringObjective.meta() != null) { ObjectNode trafficTreatmentNode = trafficTreatmentCodec.encode(filteringObjective.meta(), context); result.set(META, trafficTreatmentNode); } ArrayNode conditions = context.mapper().createArrayNode(); filteringObjective.conditions().forEach(c -> { ObjectNode criterionJson = criterionCodec.encode(c, context); conditions.add(criterionJson); }); result.set(CONDITIONS, conditions); return result; }  @Override ObjectNode encode(FilteringObjective filteringObjective, CodecContext context); @Override FilteringObjective decode(ObjectNode json, CodecContext context); static final String REST_APP_ID; }