I have a simple DTO that I would like to receive as a JSON and deserialize using Jackson's ObjectMapper
class SimpleDto {
LocalDate date;
}
The problem is that the format of this date, however should be yyyy-MM-dd
, is not fixed and it can miss some parts - e.g. it can be full date
{
"date": "2020-01-01"
}
or just year with month without day
{
"date": "2020-01"
}
or even just a year
{
"date": "2020"
}
I'm trying to use ObjectMapper
with JavaTimeModule
registered but it does not support e.g. year without month and day format
ObjectMapper mapper = new ObjectMapper().registerModule(JavaTimeModule());
is it possible to map it somehow to LocalDate
? I saw some similar topics (like this) but seems that they're do not answer my question
EDIT
Now I'm starting to think should I treat this field as a LocalDate
- as far as I understand there's nothing like LocalDate.of(2000, 0, 0)
(and actually it's throwing exception) then deserializing 1990
to (what?) 1990-01-01
is obviously an error and could cause some exceptions in a logic that would assume that 01
is a valid and provided month and 01
is a valid and provided day