@Override
    public ObjectNode encode(DelayMeasurementCreate dm, CodecContext context) {
        checkNotNull(dm, "DM cannot be null");
        ObjectNode result = context.mapper().createObjectNode()
                .put(DM_CFG_TYPE, dm.dmCfgType().name())
                .put(VERSION, dm.version().name())
                .put(REMOTE_MEP_ID, dm.remoteMepId().id())
                .put(PRIORITY, dm.priority().name());

        if (dm.measurementsEnabled() != null) {
            result.set(MEASUREMENTS_ENABLED, new DmMeasurementOptionCodec()
                    .encode(dm.measurementsEnabled(), context));
        }

        if (dm.messagePeriod() != null) {
            result.put(MESSAGE_PERIOD_MS, dm.messagePeriod().toMillis());
        }
        if (dm.frameSize() != null) {
            result.put(FRAME_SIZE, dm.frameSize());
        }


        return result;
    }
@Test
    public void testEncodeDelayMeasurementCreateCodecContext()
            throws SoamConfigException {
        DmCreateBuilder builder = DefaultDelayMeasurementCreate
                .builder(DmType.DM1DMRX, Version.Y17312011,
                        MepId.valueOf((short) 16), Priority.PRIO5);
        builder.addToMeasurementsEnabled(
                MeasurementOption.FRAME_DELAY_BACKWARD_MAX);
        builder.addToMeasurementsEnabled(
                MeasurementOption.FRAME_DELAY_TWO_WAY_MAX);
        builder.addToMeasurementsEnabled(
                MeasurementOption.INTER_FRAME_DELAY_VARIATION_BACKWARD_BINS);
        builder = (DmCreateBuilder) builder.messagePeriod(Duration.ofMillis(100));
        builder = (DmCreateBuilder) builder.frameSize((short) 1200);

        ObjectNode node = mapper.createObjectNode();
        node.set("dm", context.codec(DelayMeasurementCreate.class)
                .encode(builder.build(), context));

        assertEquals(DmType.DM1DMRX.name(), node.get("dm").get("dmCfgType").asText());
        assertEquals(Version.Y17312011.name(), node.get("dm").get("version").asText());
        assertEquals(16, node.get("dm").get("remoteMepId").asInt());
        assertEquals(Priority.PRIO5.name(), node.get("dm").get("priority").asText());
        assertEquals(100, node.get("dm").get("messagePeriodMs").asInt());
        assertEquals(1200, node.get("dm").get("frameSize").asInt());

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