A Web service returns "location" objects with properties that map almost 1:1 to the fields of android.location.Address. I've written a custom deserializer to handle them, and it works.
Occasionally the Web service returns garbage locations, i.e., latitude 0.0, longitude 0.0, other fields empty strings. I'd like these garbage locations to be deserialized as a Java null.
Is JsonDeserializer#deserialize(...) allowed to return null?
I haven't simply tested this myself because:
JsonDeserializer#deserialize is allowed to return null by the design of JsonDeserializer class, although it is not explicitly mentioned in the Javadoc of the method.
This can be assumed by the existence, default implementation and documentation of methods JsonDeserializer#getNullValue and JsonDeserializer#getEmptyValue.
These methods can be called to produce return values for deserialize e.g.
return getNullValue();
when the JsonToken is null or empty respectively. By default they return null and that will be returned by deserialize.
See here an example with getNullValue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With