@Override
    public ObjectNode encode(MultiPointToSinglePointIntent intent, CodecContext context) {
        checkNotNull(intent, "Multi Point to Single Point intent cannot be null");

        final JsonCodec<ConnectivityIntent> connectivityIntentCodec =
                context.codec(ConnectivityIntent.class);
        final ObjectNode result = connectivityIntentCodec.encode(intent, context);

        final JsonCodec<ConnectPoint> connectPointCodec =
                context.codec(ConnectPoint.class);
        final ObjectNode egress =
                connectPointCodec.encode(intent.egressPoint(), context);

        // Check ingress are not null and not contain egress
        ObjectNode objectCP = context.mapper().createObjectNode();
        ArrayNode jsonconnectPoints = objectCP.putArray(CP_POINTS);

        if (intent.ingressPoints() != null) {
            for (final ConnectPoint cp : intent.ingressPoints()) {
                jsonconnectPoints.add(connectPointCodec.encode(cp, context));
            }
            result.set(INGRESS_POINT, jsonconnectPoints);
        }
        result.set(EGRESS_POINT, egress);
        return result;
    }
@Test
    public void encodeMultiPointToSinglePointIntent() {

        final MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder()
                .appId(APPID)
                .selector(MATCH)
                .treatment(NOP)
                .filteredIngressPoints(FPS1)
                .filteredEgressPoint(FP2)
                .build();

        assertThat(intent, notNullValue());
        assertThat(intent, instanceOf(MultiPointToSinglePointIntent.class));

        final JsonCodec<MultiPointToSinglePointIntent> intentCodec =
                context.codec(MultiPointToSinglePointIntent.class);
        assertThat(intentCodec, notNullValue());

        final ObjectNode result = intentCodec.encode(intent, context);

        assertThat(result.get("type").textValue(), is("MultiPointToSinglePointIntent"));
        assertThat(result.get("id").textValue(), is("0x0"));
        assertThat(result.get("appId").textValue(), is("foo"));
        assertThat(result.get("priority").asInt(), is(100));

        boolean found1 = false;
        boolean found3 = false;
        for (int i = 0; i < FPS1.size(); i++) {
            String portString = result.get("ingressPoint").get(i).get("port").textValue();
            if (portString.equals("1")) {
                found1 = true;
            } else if (portString.equals("3")) {
                found3 = true;
            }
        }
        assertThat("Port 1 was not found", found1, is(true));
        assertThat("Port 3 was not found", found3, is(true));

        assertThat(result.get("egressPoint").get("port").textValue(), is("2"));
        assertThat(result.get("egressPoint").get("device").textValue(), is("222"));
    }