1

I have a spring boot app and the following DTO class:

public class CarDto {
    private Map<Instant, List<CarModelDto>> dateToCarModels = new HashMap<>();

    // getters/setters omitted for brevity
}

When I make a call from postman it looks like this:

{
    "dateToCarModels": {
        "1544612555": [{
            <obj1>
        },
        {
            <obj2>
        }],
        "1544785355": [{
            <obj1>
        }]
    }
}

It gives me the following error:

JSON parse error: Cannot deserialize Map key of type
`java.time.Instant` from String "1544612555": Failed to deserialize
java.time.Instant: (java.time.format.DateTimeParseException) Text
'1544612555' could not be parsed at index 0; nested exception is
com.fasterxml.jackson.databind.exc.InvalidFormatException: (...)

That is understandable as I have Instant as a key map (and pass String in json - since JSON keys must be strings).

Is there any better way to fix it than writting own key serializer/deserializer ?

user3529850
  • 1,632
  • 5
  • 32
  • 51

0 Answers0