FasterXML / jackson-modules-java8

Set of support modules for Java 8 datatypes (Optionals, date/time) and features (parameter names)
Apache License 2.0
398 stars 116 forks source link

Issues in parsing java8 date time object with Spring Boot #268

Closed pawar-kapil closed 1 year ago

pawar-kapil commented 1 year ago

After upgrading from springboot 2.4.0 to 2.6.0, we have started recieving this error: org.springframework.data.redis.serializer.SerializationException: Could not write JSON: Java 8 date/time typejava.time.OffsetDateTimenot supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: MyDTO["createdOn"]); nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time typejava.time.OffsetDateTimenot supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: MyDTO["createdOn"]) .

The objectmapper configurations that I have set are as follows:

mapper = new ObjectMapper();
        mapper.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        mapper.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, false);
        ClassLoader classLoader = ObjectMapperContextResolver.class.getClassLoader();
        if (ClassUtils.isPresent("org.hibernate.proxy.HibernateProxy", classLoader)) {

            mapper.registerModule(new com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module().disable(
                            com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module.Feature.USE_TRANSIENT_ANNOTATION));
        }
        mapper.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);

The versions that I'm using are: jackson-databind:2.13.0 jackson-datatype-jsr310:2.13.0 spring-boot:2.6.0

cowtowncoder commented 1 year ago

This looks like a Spring issue with configuration, so you will need to work with Spring support / issue trackers. We do not troubleshoot issues wrt configuration of 3rd party libraries or frameworks, although we work with their maintainers as needed (to help them integrate).

If you could show a Jackson-only reproduction of the issue we could help, but I think here specifically that is not possible.

cowtowncoder commented 1 year ago

Cannot reproduce without stand-alone test; closing, may be reopened with such test (but recommend going via Spring support route first)