@JsonDeserialize does not work for null json value in this case. it is throwing error
// I have the following json string.
{
"myCount": null
}
//class
public class Test {
// @JsonDeserialize does not work for null json value in this case. it is throwing error.
@JsonDeserialize (using = Custom.class)
private double myCount;
}
//Custom deserializer
public class Custom extends JsonDeserializer<Double> {
//implements deserialize method
@Override
public Double deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
String text = jp.getText();
if (text == null || text.isEmpty()) {
return null;
} else {
return Double.valueOf(text);
}
}
}
}
please let me know. Thanks