org.springframework.http.converter.HttpMessageNotReadableException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • I have a project like: {code:java} @Entity public class Store { @Id public Long id; @OneToMany @JsonIgnore public Set<Hours> hours; @OneToMany @JsonIgnore public Set<HourOverrides> overrides; public TodaysHours getTodaysHoursComputedValue() { TodayHours todaysHours = //computation based on hours and overrides return todaysHours; } public setTodaysHoursComputedValue() { //Do nothing, just needed so that jackson has a corresponding setter to call, but value is discarded } {code} I have a separate manual controller that handles {code}/stores/{id}/hours{code} and lets your CRUD against a DTO containing both hours and overrides - so I *do not* want to expose those values directly on the Store, but i do want to expose a read-only version of the hours. In DomainObjectReader there is the call to: {code:java}final MappedProperties properties = getJacksonProperties(entity, mapper);{code} which returns all the properties jackson knows about. Then for each of those it calls: {code:java}PersistentProperty<?> persistentProperty = entity.getPersistentProperty(property.getInternalName());{code} which in the case of this, returns null as this is a COMPUTED value and doesn't map to a persisted entity. The problem is that even though there IS no persistent property it adds the null to a couple of {code:java}propertyToFieldName.put(persistentProperty, property.getName()); fieldNameToProperty.put(property.getName(), persistentProperty);{code} which are later dereferenced and leads to an NPE. {code}Caused by: java.lang.NullPointerException at org.springframework.data.mapping.model.BeanWrapper.getProperty(BeanWrapper.java:96) ~[spring-data-commons-1.11.0.M1.jar:?] at org.springframework.data.rest.webmvc.json.DomainObjectReader.doMerge(DomainObjectReader.java:185) ~[spring-data-rest-webmvc-2.4.0.M1.jar:?] at org.springframework.data.rest.webmvc.json.DomainObjectReader.merge(DomainObjectReader.java:136) ~[spring-data-rest-webmvc-2.4.0.M1.jar:?] at org.springframework.data.rest.webmvc.json.DomainObjectReader.readPut(DomainObjectReader.java:130) ~[spring-data-rest-webmvc-2.4.0.M1.jar:?] at org.springframework.data.rest.webmvc.config.JsonPatchHandler.applyPut(JsonPatchHandler.java:134) ~[spring-data-rest-webmvc-2.4.0.M1.jar:?]{code} I believe the fix would be on {{DomainObjectReader.java:237}} to add a null check before adding the nulls to those maps. It seems like you should be able to have computed values in your response and to simply ignore them on the deserialization if the client happens to pass them. I know it's a bit of a hack in jackson to have a getter with an empty setter for computed properties - but this is getting full support in jackson 2.6 (https://github.com/FasterXML/jackson-databind/issues/95) - and i believe it's a valid use case. Please let me know if you disagree, or if you know of any work arounds.
    via by Ben Madore,
  • I have a project like: {code:java} @Entity public class Store { @Id public Long id; @OneToMany @JsonIgnore public Set<Hours> hours; @OneToMany @JsonIgnore public Set<HourOverrides> overrides; public TodaysHours getTodaysHoursComputedValue() { TodayHours todaysHours = //computation based on hours and overrides return todaysHours; } public setTodaysHoursComputedValue() { //Do nothing, just needed so that jackson has a corresponding setter to call, but value is discarded } {code} I have a separate manual controller that handles {code}/stores/{id}/hours{code} and lets your CRUD against a DTO containing both hours and overrides - so I *do not* want to expose those values directly on the Store, but i do want to expose a read-only version of the hours. In DomainObjectReader there is the call to: {code:java}final MappedProperties properties = getJacksonProperties(entity, mapper);{code} which returns all the properties jackson knows about. Then for each of those it calls: {code:java}PersistentProperty<?> persistentProperty = entity.getPersistentProperty(property.getInternalName());{code} which in the case of this, returns null as this is a COMPUTED value and doesn't map to a persisted entity. The problem is that even though there IS no persistent property it adds the null to a couple of {code:java}propertyToFieldName.put(persistentProperty, property.getName()); fieldNameToProperty.put(property.getName(), persistentProperty);{code} which are later dereferenced and leads to an NPE. {code}Caused by: java.lang.NullPointerException at org.springframework.data.mapping.model.BeanWrapper.getProperty(BeanWrapper.java:96) ~[spring-data-commons-1.11.0.M1.jar:?] at org.springframework.data.rest.webmvc.json.DomainObjectReader.doMerge(DomainObjectReader.java:185) ~[spring-data-rest-webmvc-2.4.0.M1.jar:?] at org.springframework.data.rest.webmvc.json.DomainObjectReader.merge(DomainObjectReader.java:136) ~[spring-data-rest-webmvc-2.4.0.M1.jar:?] at org.springframework.data.rest.webmvc.json.DomainObjectReader.readPut(DomainObjectReader.java:130) ~[spring-data-rest-webmvc-2.4.0.M1.jar:?] at org.springframework.data.rest.webmvc.config.JsonPatchHandler.applyPut(JsonPatchHandler.java:134) ~[spring-data-rest-webmvc-2.4.0.M1.jar:?]{code} I believe the fix would be on {{DomainObjectReader.java:237}} to add a null check before adding the nulls to those maps. It seems like you should be able to have computed values in your response and to simply ignore them on the deserialization if the client happens to pass them. I know it's a bit of a hack in jackson to have a getter with an empty setter for computed properties - but this is getting full support in jackson 2.6 (https://github.com/FasterXML/jackson-databind/issues/95) - and i believe it's a valid use case. Please let me know if you disagree, or if you know of any work arounds.
    via by Ben Madore,
    • org.springframework.http.converter.HttpMessageNotReadableException: Could not read an object of type class example.Item from the request!; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Could not read payload!; nested exception is java.lang.NullPointerException at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.readPatch(PersistentEntityResourceHandlerMethodArgumentResolver.java:183) at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.read(PersistentEntityResourceHandlerMethodArgumentResolver.java:160) at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.resolveArgument(PersistentEntityResourceHandlerMethodArgumentResolver.java:125) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:78) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:775) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:840) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: org.springframework.http.converter.HttpMessageNotReadableException: Could not read payload!; nested exception is java.lang.NullPointerException at org.springframework.data.rest.webmvc.json.DomainObjectReader.read(DomainObjectReader.java:89) at org.springframework.data.rest.webmvc.config.JsonPatchHandler.applyMergePatch(JsonPatchHandler.java:130) at org.springframework.data.rest.webmvc.config.JsonPatchHandler.apply(JsonPatchHandler.java:99) at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.readPatch(PersistentEntityResourceHandlerMethodArgumentResolver.java:181) ... 42 more Caused by: java.lang.NullPointerException: null at org.springframework.data.mapping.model.BeanWrapper.getProperty(BeanWrapper.java:102) at org.springframework.data.rest.webmvc.json.DomainObjectReader.doMerge(DomainObjectReader.java:185) at org.springframework.data.rest.webmvc.json.DomainObjectReader.read(DomainObjectReader.java:87) ... 45 more

    Users with the same issue

    Unknown visitor
    Unknown visitor1 times, last one,