@Test public void alarmCodecTestWithOptionalFieldMissing() { JsonCodec<Alarm> codec = context.codec(Alarm.class); assertThat(codec, is(notNullValue())); ObjectNode alarmJson = codec.encode(alarmMinimumFields, context); assertThat(alarmJson, notNullValue()); assertThat(alarmJson, matchesAlarm(alarmMinimumFields)); }
@Override public ObjectNode encode(Alarm alarm, CodecContext context) { checkNotNull(alarm, "Alarm cannot be null"); return context.mapper().createObjectNode() .put("id", alarm.id().fingerprint()) .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()); }
AlarmCodec extends JsonCodec<Alarm> { @Override public ObjectNode encode(Alarm alarm, CodecContext context) { checkNotNull(alarm, "Alarm cannot be null"); return context.mapper().createObjectNode() .put("id", alarm.id().fingerprint()) .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()); } }
AlarmCodec extends JsonCodec<Alarm> { @Override public ObjectNode encode(Alarm alarm, CodecContext context) { checkNotNull(alarm, "Alarm cannot be null"); return context.mapper().createObjectNode() .put("id", alarm.id().fingerprint()) .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()); }  }
AlarmCodec extends JsonCodec<Alarm> { @Override public ObjectNode encode(Alarm alarm, CodecContext context) { checkNotNull(alarm, "Alarm cannot be null"); return context.mapper().createObjectNode() .put("id", alarm.id().fingerprint()) .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()); }  @Override ObjectNode encode(Alarm alarm, CodecContext context); @Override Alarm decode(ObjectNode json, CodecContext context); }
AlarmCodec extends JsonCodec<Alarm> { @Override public ObjectNode encode(Alarm alarm, CodecContext context) { checkNotNull(alarm, "Alarm cannot be null"); return context.mapper().createObjectNode() .put("id", alarm.id().fingerprint()) .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()); }  @Override ObjectNode encode(Alarm alarm, CodecContext context); @Override Alarm decode(ObjectNode json, CodecContext context);  }