@Test public void shouldReturnReadingIfValueIsNotEmptyAndNRIsNull() throws Exception { JsonNode valueNode = mock(JsonNode.class); when(valueNode.asText()).thenReturn("55"); when(jsonNode.get("value")).thenReturn(valueNode); when(jsonNode.get("notRecorded")).thenReturn(null); Reading reading = new DistributionReadingDeSerializer().deserialize(jp, mock(DeserializationContext.class)); assertThat(reading.getValue(), is("55")); }
@Override public Reading deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectCodec objectCodec = jp.getCodec(); JsonNode jsonNode = objectCodec.readTree(jp); JsonNode value = jsonNode.get("value"); JsonNode notRecorded = jsonNode.get("notRecorded"); String stringValue = value != null ? value.asText() : null; Boolean notRecordedValue = notRecorded != null && notRecorded.booleanValue(); return new Reading(stringValue, notRecordedValue); }
DistributionReadingDeSerializer extends JsonDeserializer<Reading> { @Override public Reading deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectCodec objectCodec = jp.getCodec(); JsonNode jsonNode = objectCodec.readTree(jp); JsonNode value = jsonNode.get("value"); JsonNode notRecorded = jsonNode.get("notRecorded"); String stringValue = value != null ? value.asText() : null; Boolean notRecordedValue = notRecorded != null && notRecorded.booleanValue(); return new Reading(stringValue, notRecordedValue); } }
DistributionReadingDeSerializer extends JsonDeserializer<Reading> { @Override public Reading deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectCodec objectCodec = jp.getCodec(); JsonNode jsonNode = objectCodec.readTree(jp); JsonNode value = jsonNode.get("value"); JsonNode notRecorded = jsonNode.get("notRecorded"); String stringValue = value != null ? value.asText() : null; Boolean notRecordedValue = notRecorded != null && notRecorded.booleanValue(); return new Reading(stringValue, notRecordedValue); }  }
DistributionReadingDeSerializer extends JsonDeserializer<Reading> { @Override public Reading deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectCodec objectCodec = jp.getCodec(); JsonNode jsonNode = objectCodec.readTree(jp); JsonNode value = jsonNode.get("value"); JsonNode notRecorded = jsonNode.get("notRecorded"); String stringValue = value != null ? value.asText() : null; Boolean notRecordedValue = notRecorded != null && notRecorded.booleanValue(); return new Reading(stringValue, notRecordedValue); }  @Override Reading deserialize(JsonParser jp, DeserializationContext ctxt); }
DistributionReadingDeSerializer extends JsonDeserializer<Reading> { @Override public Reading deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { ObjectCodec objectCodec = jp.getCodec(); JsonNode jsonNode = objectCodec.readTree(jp); JsonNode value = jsonNode.get("value"); JsonNode notRecorded = jsonNode.get("notRecorded"); String stringValue = value != null ? value.asText() : null; Boolean notRecordedValue = notRecorded != null && notRecorded.booleanValue(); return new Reading(stringValue, notRecordedValue); }  @Override Reading deserialize(JsonParser jp, DeserializationContext ctxt);  }