Fix for ONOS-7960 - single to multi intent json codec can't decode egress point array
Change-Id: I55463701ff080be7ed857f72e29878c98c55dc13
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/SinglePointToMultiPointIntentCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/SinglePointToMultiPointIntentCodec.java
index 6d56b25..a0ae922 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/SinglePointToMultiPointIntentCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/SinglePointToMultiPointIntentCodec.java
@@ -15,15 +15,14 @@
*/
package org.onosproject.codec.impl;
-import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.FilteredConnectPoint;
import org.onosproject.net.intent.ConnectivityIntent;
import org.onosproject.net.intent.SinglePointToMultiPointIntent;
-import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.HashSet;
import java.util.Set;
@@ -37,7 +36,6 @@
public class SinglePointToMultiPointIntentCodec extends JsonCodec<SinglePointToMultiPointIntent> {
private static final String INGRESS_POINT = "ingressPoint";
private static final String EGRESS_POINT = "egressPoint";
- private static final String CP_POINTS = "connectPoints";
@Override
public ObjectNode encode(SinglePointToMultiPointIntent intent, CodecContext context) {
@@ -52,8 +50,7 @@
final ObjectNode ingress =
connectPointCodec.encode(intent.ingressPoint(), context);
- final ObjectNode result2 = context.mapper().createObjectNode();
- final ArrayNode jsonconnectPoints = result2.putArray(CP_POINTS);
+ final ArrayNode jsonconnectPoints = context.mapper().createArrayNode();
if (intent.egressPoints() != null) {
for (final ConnectPoint cp : intent.egressPoints()) {
@@ -79,22 +76,19 @@
.decode(ingressJson, context);
builder.filteredIngressPoint(new FilteredConnectPoint(ingress));
- ObjectNode egressJson = nullIsIllegal(get(json, EGRESS_POINT),
- EGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
- if (egressJson != null) {
- final JsonCodec<ConnectPoint> connectPointCodec =
- context.codec(ConnectPoint.class);
- JsonNode connectPointsJson = get(json, EGRESS_POINT).get(CP_POINTS);
+ ArrayNode egressJson = nullIsIllegal((ArrayNode) json.get(EGRESS_POINT),
+ EGRESS_POINT + IntentCodec.MISSING_MEMBER_MESSAGE);
- Set<FilteredConnectPoint> egressCp = new HashSet<>();
- if (connectPointsJson != null) {
- for (int i = 0; i < connectPointsJson.size(); i++) {
- ConnectPoint cp = connectPointCodec.decode(get(connectPointsJson, i), context);
- egressCp.add(new FilteredConnectPoint(cp));
- }
- builder.filteredEgressPoints(egressCp);
- }
+ final JsonCodec<ConnectPoint> connectPointCodec =
+ context.codec(ConnectPoint.class);
+
+ Set<FilteredConnectPoint> egressCp = new HashSet<>();
+
+ for (int i = 0; i < egressJson.size(); i++) {
+ ConnectPoint cp = connectPointCodec.decode(get(egressJson, i), context);
+ egressCp.add(new FilteredConnectPoint(cp));
}
+ builder.filteredEgressPoints(egressCp);
return builder.build();
}