I have a class which looks like below:
class A {
Map<String, LocalDate> mapLocalDate;
Map<String, String> simpleMap;
String name;
}
This class should be converted to Map < String, Object >, where the key is the attribute name and the value is attribute value. To do so I use the Jackson ObjectMapper:
final ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new Jdk8Module());
objectMapper.registerModules(new JavaTimeModule());
objectMapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
objectMapper.configure(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS, false);
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
final Map<String, Object> fieldMap = this.objectMapper.convertValue(entityA, Map.class)
This approach works fine for simple fields like: "simpleMap", "name". But not for one with value LocalDate (field name: "mapLocalDate") The convertation throw the bellow error:
java.util.Date cannot be cast to java.time.LocalDate
Maybe somebody faced a similar issue and could suggest what is wrong in configurations?