The API in question is not documented so it is not clear which properties are nullable on the JSON response. Some properties are currently null and some properties might be null but currently contain a value. I discover new nullable properties as I request more data. A simple very small example...
{
"account": {
"price": 12.34,
"tax": null,
"discount": 5.00,
"specialSomething": 12.34 // might be nullable, not documented,
"anotherSomething": null // wasn't null until the 5th page of results
}
}
What is the best practice for deserializing objects from a JSON response where properties may or may not be null and documentation is lacking.
Do you make all properties on the POJO (Plain Old Java Object) optional? That is a bit of a pain to map to a view model. Check that every optional has a value.
Do you just make properties optional as you go? Letting the app crash when suddenly a JSON property is null and do a hotfix?
Do you halt production until you get documentation for the API? Even if this takes weeks?
Mapping data model changes to property name or even response structures to the same Domain model is not a problem. However, when a response property suddenly becomes null, that’s an entirely different data Type, and changes ripple out through the Domain model to the Presentation layer.
How do I insulate the domain model from null property changes in the data model?