@Override
    public ObjectNode encode(MepEntry mepEntry, CodecContext context) {
        checkNotNull(mepEntry, "Mep cannot be null");

        ObjectNode result = context.mapper().createObjectNode();

        //Get the common attributes
        Mep mep = mepEntry;
        ObjectNode mepAttrs = new MepCodec().encode(mep, context);
        Iterator<Entry<String, JsonNode>> elements = mepAttrs.fields();
        while (elements.hasNext()) {
            Entry<String, JsonNode> element = elements.next();
            result.set(element.getKey(), element.getValue());
        }

        if (mepEntry.macAddress() != null) {
            result.put("macAddress", mepEntry.macAddress().toString());
        }

        if (mepEntry.loopbackAttributes() != null) {
            result.set("loopback", new MepLbEntryCodec()
                    .encode(mepEntry.loopbackAttributes(), context));
        }

        if (mepEntry.activeRemoteMepList() != null) {
            result.set("remoteMeps", new RemoteMepEntryCodec()
                    .encode(mepEntry.activeRemoteMepList(), context));
        }

        if (mepEntry.activeErrorCcmDefect()) {
            result.put("activeErrorCcmDefect", true);
        }
        if (mepEntry.activeMacStatusDefect()) {
            result.put("activeMacStatusDefect", true);
        }
        if (mepEntry.activeRdiCcmDefect()) {
            result.put("activeRdiCcmDefect", true);
        }
        if (mepEntry.activeRemoteCcmDefect()) {
            result.put("activeRemoteCcmDefect", true);
        }
        if (mepEntry.activeXconCcmDefect()) {
            result.put("activeXconCcmDefect", true);
        }
        return result;
    }
@Test
    public void testEncodeIterableOfMepEntryCodecContext() throws CfmConfigException {
        MepEntry mepEntry2 = DefaultMepEntry.builder(
                MepId.valueOf((short) 33),
                DeviceId.deviceId("netconf:4321:830"),
                PortNumber.portNumber(1),
                MepDirection.DOWN_MEP,
                MdIdCharStr.asMdId("md-2"),
                MaIdCharStr.asMaId("ma-2-2"))
            .buildEntry();

        ArrayList<MepEntry> meps = new ArrayList<>();
        meps.add(mepEntry1);
        meps.add(mepEntry2);

        ObjectNode node = mapper.createObjectNode();
        node.set("mep", context.codec(MepEntry.class)
                .encode(meps, context));

        Iterator<JsonNode> an = node.get("mep").elements();
        while (an.hasNext()) {
            JsonNode jn = an.next();
            assertEquals("md-", jn.get("mdName").asText().substring(0, 3));
        }
    }