@Override
    public ObjectNode encode(DelayMeasurementEntry dm, CodecContext context) {
        checkNotNull(dm, "DM cannot be null");
        ObjectNode result = context.mapper().createObjectNode()
                .put(DM_ID, dm.dmId().toString());

        if (dm.sessionStatus() != null) {
            result.put(SESSION_STATUS, dm.sessionStatus().name());
        }
        if (dm.frameDelayTwoWay() != null) {
            result.put(FRAME_DELAY_TWO_WAY, dm.frameDelayTwoWay().toString());
        }
        if (dm.frameDelayForward() != null) {
            result.put(FRAME_DELAY_FORWARD, dm.frameDelayForward().toString());
        }
        if (dm.frameDelayBackward() != null) {
            result.put(FRAME_DELAY_BACKWARD, dm.frameDelayBackward().toString());
        }
        if (dm.interFrameDelayVariationTwoWay() != null) {
            result.put(INTER_FRAME_DELAY_VARIATION_TWO_WAY,
                    dm.interFrameDelayVariationTwoWay().toString());
        }
        if (dm.interFrameDelayVariationForward() != null) {
            result.put(INTER_FRAME_DELAY_VARIATION_FORWARD,
                    dm.interFrameDelayVariationForward().toString());
        }
        if (dm.interFrameDelayVariationBackward() != null) {
            result.put(INTER_FRAME_DELAY_VARIATION_BACKWARD,
                    dm.interFrameDelayVariationBackward().toString());
        }

        ObjectNode dmAttrs = new DmCreateCodec().encode(dm, context);
        Iterator<Entry<String, JsonNode>> elements = dmAttrs.fields();
        while (elements.hasNext()) {
            Entry<String, JsonNode> element = elements.next();
            result.set(element.getKey(), element.getValue());
        }

        if (dm.currentResult() != null) {
            result.set(CURRENT, new DelayMeasurementStatCurrentCodec()
                    .encode(dm.currentResult(), context));
        }

        if (dm.historicalResults() != null) {
            result.set(HISTORIC, new DelayMeasurementStatHistoryCodec()
                    .encode(dm.historicalResults(), context));
        }

        return result;
    }
@Test
    public void testEncodeIterableOfDelayMeasurementEntryCodecContext()
            throws SoamConfigException {
        DmEntryBuilder builder2 = DefaultDelayMeasurementEntry
                .builder(SoamId.valueOf(14), DmType.DM1DMRX,
                        Version.Y17312011, MepId.valueOf((short) 16), Priority.PRIO5);
        builder2.addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_BACKWARD_MIN);
        builder2.addToMeasurementsEnabled(MeasurementOption.FRAME_DELAY_TWO_WAY_MIN);
        builder2.addToMeasurementsEnabled(MeasurementOption.INTER_FRAME_DELAY_VARIATION_BACKWARD_MIN);

        Collection<DelayMeasurementEntry> dmEntries = new ArrayList<>();
        dmEntries.add(dmEntry1);
        dmEntries.add(builder2.build());
        ObjectNode node = mapper.createObjectNode();
        node.set("dm", context.codec(DelayMeasurementEntry.class)
                .encode(dmEntries, context));

        assertEquals(2, ((ArrayNode) node.get("dm")).size());
    }