-
Notifications
You must be signed in to change notification settings - Fork 40.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring Boot 2.5.0 and InvalidDefinitionException: Java 8 date/time type java.time.Instant
not supported by default
#26859
Comments
There are several people already trying to help on Stack Overflow. To avoid duplication of effort, let’s keep things in one place for now please. We can re-open this issue if a bug is identified and a change in Spring Boot is required. |
@wilkinsona - I think this is a bug. For me, I get the same error when calling the /actuator/info endpoint : 2021-06-14 14:46:23.897 ERROR 1500 --- [io-19019-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class java.time.Instant]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.Instant` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: java.util.Collections$UnmodifiableMap["git"]->java.util.LinkedHashMap["commit"]->java.util.LinkedHashMap["time"])] with root cause
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.Instant` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling (through reference chain: java.util.Collections$UnmodifiableMap["git"]->java.util.LinkedHashMap["commit"]->java.util.LinkedHashMap["time"])
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1276) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.impl.UnsupportedTypeSerializer.serialize(UnsupportedTypeSerializer.java:35) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:808) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeWithoutTypeInfo(MapSerializer.java:764) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:720) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:35) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:808) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeWithoutTypeInfo(MapSerializer.java:764) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:720) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:35) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:808) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeWithoutTypeInfo(MapSerializer.java:764) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:720) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:35) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1514) ~[jackson-databind-2.12.3.jar:2.12.3]
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:1006) ~[jackson-databind-2.12.3.jar:2.12.3]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:454) ~[spring-web-5.3.8.jar:5.3.8]
at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:104) ~[spring-web-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:290) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:181) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:78) ~[spring-web-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:124) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.boot.actuate.autoconfigure.web.servlet.CompositeHandlerAdapter.handle(CompositeHandlerAdapter.java:58) ~[spring-boot-actuator-autoconfigure-2.5.1.jar:2.5.1]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1063) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.8.jar:5.3.8]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:626) ~[tomcat-embed-core-9.0.46.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.8.jar:5.3.8]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.46.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:327) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:121) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:126) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:81) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:105) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:149) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:89) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.8.jar:5.3.8]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:110) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.8.jar:5.3.8]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:211) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183) ~[spring-security-web-5.5.0.jar:5.5.0]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1707) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.46.jar:9.0.46]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na] |
@oridool 2.5.x should automatically register the JSR-310 module when it's available on the classpath just as 2.4.x does. Our own Actuator API documentation for the In this case the module is one that is known to Spring Framework's |
thanks @wilkinsona . |
I confirm this issue. I think 2.5.x does show up this issue out of different issues. I think the common thing i see is, that other libraries also including js310, use 2.11 and not 2.12. Candidates
So when using springfox < 3.0.0 (which just has been released) people run into the same issue (#26685) So i assume not all projects run into this issue, only those, who use other dependencies which include an < 2.12 jackson jsr303 wich then is not compatible during runtime and cannot be used. the reason is, that scanning the classpath for the right one can lead to the first, older one. You can check the ones you have in your classpath by running
|
@EugenMayer ,
|
@oridool then there is probably even more to it. It is absolutely sure that this is related to SB 2.5 and the jaxon upgrade. Yet i assumed a version mix up alone is enough, maybe there is even more to it: I could isolate and reproduce this issue with our project in a test. Upgrading to 2.5.1 leads to the issue, downgrading fixes it. |
Update:
|
regarding the first solution. can you provide the class that generate the bean and did you remove it? |
@eranf91 , @Bean
public ObjectMapper objectMapper() {
return new ObjectMapper();
} I don't think it can be considered as as springboot issue. |
If you define your own Nothing should have changed in this area in Spring Boot 2.5. If someone can provide a minimal sample application that works with 2.4.x and then fails after upgrading to 2.5.x, we will happily take a look. |
@wilkinsona , In this app, I use my own ObjectMapper (and without any customizations) .
This can explain why the issue did not pop up before the upgrade to 2.5.1. After upgrading to 2.5.1 , it reverts to default behavior and tries to return the time as an ISO8601 string.
The default response, if I remove my
|
Thanks for the sample. Spring Boot upgraded to Jackson 2.12 which contains this change. As a result, if an attempt is made to serialise a |
@wilkinsona i'am not sure this is the only cause, but it is a good case. I guess there are cases where jsr310 was never used and yet was not leading to any issues (due to the fallback in jackson 2.11) - this changed with 2.5.x and thus errors are thrown. It is though, not explained, why so many people are affected, IMHO. So the only possible reason here then is either
The question then is, how can i check 2. and how can 2. be done right? First part is for analysis, the next part is for actually fixing it. For example i use the builder customizer
Did that already reset the autoconfiguration (i though using the builder this would not happen) |
No, using a builder customizer will not disable the auto-configuration. The various options for configuration Jackson and the effect that they will have on the auto-configuration are described in the documentation that I linked to above. As described in the documentation, defining an If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. |
This is a bug. This issue should not be closed. |
@eranf91 the point is, that yet @wilkinsona does not believe that there is a spring boot issue. I fully support what you just said. a) The issue does not only exist when someone has a custom ObjectMapper and thus willingly has a disabled jsr310 support (this is not a spring boot issue, but rather by desing and an configuration issue). b) The issue also exists when one does not ovveride the jackson mapper at all. What you propose is a hot fix in this cases, basically doing a) and enabling jsr310 manually, instead of spring boot doing it in the auto configuration. |
@eranf91 Sorry, I'm not sure that I understand exactly what it is that you believe to be a bug. Let me try to clarify the situation and then we can take things from there. With Spring Boot 2.5's default configuration, serialization of One thing that has changed here is what happens when the JSR-310 module isn't available to Jackson. Due to a change in Jackson 2.12, this will now result in a serialization failure rather than Jackson limping along and serialising to an unexpected format. If you are using the auto-configured If you don't have the JSR-310 module on the classpath or have customized the |
@EugenMayer We've yet to see anyone in that situation. If you have a sample application that reproduces this behaviour then we're more than happy to take a look. |
@wilkinsona i maybe circled in on this a little more. When running an Removing This seems to have been changed with 2.5, in spring 2.4 this was not an issue. Any clues what could be a change in 2.5 causing this? |
As far as I can tell, In 2.4, this replacement of the auto-configured {
"dayOfYear":178,
"month":"JUNE",
"dayOfWeek":"SUNDAY",
"nano":345824000,
"year":2021,
"monthValue":6,
"dayOfMonth":27,
"hour":12,
"minute":7,
"second":32,
"chronology": {
"calendarType":"iso8601",
"id":"ISO"
}
} In 2.5 it fails:
This difference in Jackson's behaviour is due to the aforelinked change in Jackson 2.12. They decided that it was better to fail fast recommending the use of |
@wilkinsona i understardn your thesis. It is basically, that the ObjectMapper was not supporting jsr310 in both, 2.4 and 2.5 when using One thing i do not understand though, why does |
If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. |
The issue does not relate to the import annotation.
|
@eranf91 You are creating the @WebMvcTest(controllers = {SimpleController.class})
class SimpleControllerTest {
@Autowired
MockMvc mockMvc;
@Autowired
ObjectMapper objectMapper;
@SneakyThrows
@Test
void test(){
mockMvc.perform(post("/simple")
.contentType(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(SimpleRequest.builder()
.time(now())
.build())))
.andExpect(status().isOk());
}
} FWIW, your @WebMvcTest(controllers = {SimpleController.class})
@FieldDefaults(level = PRIVATE)
@Slf4j
class SimpleControllerTest {
@Autowired
MockMvc mockMvc;
@SneakyThrows
@Test
void test() {
ObjectMapper objectMapper = new ObjectMapper();
String body = objectMapper.writeValueAsString(Map.of("time", now().toEpochSecond()));
log.info("Send: {}", body);
mockMvc.perform(post("/simple")
.contentType(APPLICATION_JSON)
.content(body))
.andExpect(status().isOk());
}
} Due to this, it works with either Jackson 2.11 (Spring Boot 2.4) or Jackson 2.12 (Spring Boot 2.5). |
My code creates a lot of ObjectMappers but what does that have to do with the I'm not getting errors from any of my ObjectMappers. I only get error on /info. When I ran junit on stackoverflow it failed, probably depends how ObjectMapper is used. |
If one of those
Ensure that your |
This information is explaining the reason. I am in the process of migration to 2.5.5 |
Hi i was able to reproduce the issue while moving from 2.4.5 to 2.5.6. See attached test. Any suggested on how to fix it? Unzip and run with: ./gradlew clean build test |
@jorgebo10 The test fails with the following:
|
Sorry. I was able to make it work. It seems that the problem was related to SNS Autoconfiguration creating a default MappingJackson2MessageConverter that does not take into account the global ObjectMapper. |
Thanks for letting us know. As described in previous comments, the problem can be caused by anything that results in an |
This didn't work. I defined a ...
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
@Primary
public ObjectMapper primaryObjectMapper(){
ObjectMapper o = new ObjectMapper();
o.configure(DeserialiszationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
o.registerModule(new JavaTimeModule());
return o;
}
} This error is coming from Spring code. Why is this ticket not marked as a bug? |
@7-- I create a new project using Spring Boot 2.6.2 from start.spring.io and added the following code: @SpringBootApplication
public class DemoApplication {
@Bean
@Primary
public ObjectMapper primaryObjectMapper() {
return JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.addModule(new JavaTimeModule()).build();
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
} With an management.endpoints.web.exposure.include=*
management.endpoint.info.enabled=true
info.test=hello I don't get any failure so there must be something else going on with your application. Please can you provide a sample that shows the problem you're facing. |
The dependecy I'm using updated thier ObjectMapper so I don't think I'll have the issue anymore, but thank you for posting I'll try again if I see the error again. |
Hi there, It's weird because I have other applications that are basically done using the same versions and it is the only one so far with this issue. There must be some other library doing something with ObjectMapper... |
Found it! A third party library was messing with the mapper in its configuration. |
Having same problem, can you share which lib was messing up with ObjectMapper? |
It wasn't a well known open source library but a custom library created by another internal group. It's kind of hard to debug as Configuration magic can happen in many places. |
Indeed, my project is not big and I'm having trouble finding why this is happening. I will try to tailor it down to the cause and share it. Thanks for your answer anyways! |
in my case the problem was another third party library that instantiate his own ObjectMapper. |
@mmighri same as mine. Still don't know why. However, removed the bean of ObjectMapper, and it works. |
Creating a primary object mapper worked for me. I didn't need the @Autowired
private ObjectMapper primaryObjectMapper; |
You can also do the following: Include the JSR310 module:
And register the Java time module the following way: ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule()); |
@AdiedX thank you it works for me now. |
You can try adding @EnableWebMvc annotation to the main class |
wow thanks! solved my problem. and why it works? |
It's good solution. Thanks! |
@vhscom Could you please put together a sample project that replicates your issue and post a link here. If it turns out we have a bug we'll open a new issue. |
All good, Phil. I need to do a little more digging first and will send up an issue with a minimal repro if I really start tearing my hair out. So far I haven't found a way past this issue in my codebase even after following the advice in the backtrace:
I've added both that and, grasping for straws, Spring Boot Starter JSON to no avail. Let's see... |
@vhscom It looks like your application has defined its own |
Thanks @bclozel you're 100% correct. I've gone back and thumbs-upped that ref from 2021. Pulling my last code snippet as it may be misleading for others. Much appreciated!! |
@vhscom Thanks for letting us know! In your case, maybe replacing the manual |
After update from Spring Boot 2.4.5 to Spring 2.5.0 I noticed the following exceptions in the application logs:
this is my pom.xml:
I reverted to Spring Boot 2.4.5 and not everything works fine. What may be wrong with Spring Boot 2.5.0 ?
UPDATED
The same issue exists in Spring Boot 2.5.1
Corresponding question on StackOverflow https://stackoverflow.com/questions/67874510/spring-boot-2-5-0-and-invaliddefinitionexception-java-8-date-time-type-java-ti
The text was updated successfully, but these errors were encountered: