@Override
    public ObjectNode encode(Alarm alarm, CodecContext context) {
        checkNotNull(alarm, "Alarm cannot be null");

        return context.mapper().createObjectNode()
                .put("id", alarm.id().toString())
                .put("deviceId", alarm.deviceId().toString())
                .put("description", alarm.description())
                .put("source",
                     alarm.source() == null ? null
                             : alarm.source().toString())
                .put("timeRaised", alarm.timeRaised())
                .put("timeUpdated", alarm.timeUpdated())
                .put("timeCleared", alarm.timeCleared())
                .put("severity", alarm.severity().toString())
                .put("serviceAffecting", alarm.serviceAffecting())
                .put("acknowledged", alarm.acknowledged())
                .put("manuallyClearable", alarm.manuallyClearable())
                .put("assignedUser", alarm.assignedUser());

    }
@Test
    public void alarmCodecTestWithOptionalField() {
        JsonCodec<Alarm> codec = context.codec(Alarm.class);
        assertThat(codec, is(notNullValue()));

        ObjectNode alarmJson = codec.encode(alarmWithSource, context);
        assertThat(alarmJson, notNullValue());
        assertThat(alarmJson, matchesAlarm(alarmWithSource));

    }