@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 testEncodeMepEntryCodecContext() {
        ObjectNode node = mapper.createObjectNode();
        node.set("mep", context.codec(MepEntry.class).encode(mepEntry1, context));

        assertEquals(22, node.get("mep").get("mepId").asInt());
        assertEquals("aa:bb:cc:dd:ee:ff".toUpperCase(),
                node.get("mep").get("macAddress").asText());
        assertTrue(node.get("mep").get("administrative-state").asBoolean());
        assertTrue(node.get("mep").get("cci-enabled").asBoolean());
        assertEquals(Priority.PRIO1.ordinal(),
                node.get("mep").get("ccm-ltm-priority").asInt());
    }