Not sure if this is the right place to ask, as it involves a third party... But it's also related with the lang. I have a problem with Gson lib, that the api can send empty string as a date. I declared this adapter to tell Gson how to deserialize a date:
registerTypeAdapter(Date::class.java, DateDeserializer())
So when the object has a non optional
Date
, it's clear that I should throw an exception if it gets an empty string. But when
Date
is optional, I'd like to map the empty string to
null
, i.e. the date will just be assigned
null
. Not sure how to do that. It relates with lang, in that the deserializer is defined like this:
`JsonDeserializer<Date>`but I need it to work with
Date?
basically.
I can of course create a getter in my object that deserializes the date if present, but I'd like to do this directly with the parser, not "outside".