org.springframework.http.converter.HttpMessageNotReadableException: Could not read an object of type class demo.Ticket from the request!; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Could not read payload!; nested exception is java.lang.NullPointerException

Spring JIRA | Justin Lewis Salmon | 1 year ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    I'm not sure if this is a regression, but it is basically the same issue as [DATAREST-491|https://jira.spring.io/browse/DATAREST-491] and [DATAREST-605|https://jira.spring.io/browse/DATAREST-605]. I'm seeing this using spring-boot-starter-data-rest:1.3.0.M5. Check out the [demo project|https://github.com/jlsalmon/mongo_data_rest] and do the following to reproduce: Create a resource: {code} curl -v -X POST http://localhost:8080/tickets -H "Content-Type: application/json" -d '{"properties" : {"a": "1", "b": {"c": "2"}}}' {code} Try to update the properties of the resource via PUT: {code} curl -v -X PUT http://localhost:8080/tickets/5640c0b6b760828633d03cca -H "Content-Type: application/json" -d '{"properties" : {"a": "3", "b": {"c": "4"}}}' {code} The following NPE is observed: {code} org.springframework.http.converter.HttpMessageNotReadableException: Could not read an object of type class demo.Ticket 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.readPutForUpdate(PersistentEntityResourceHandlerMethodArgumentResolver.java:206) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] ... at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.28.jar:8.0.28] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25] 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.merge(DomainObjectReader.java:138) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.json.DomainObjectReader.readPut(DomainObjectReader.java:130) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.config.JsonPatchHandler.applyPut(JsonPatchHandler.java:134) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.readPutForUpdate(PersistentEntityResourceHandlerMethodArgumentResolver.java:203) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] ... 52 common frames omitted Caused by: java.lang.NullPointerException: null at org.springframework.data.rest.webmvc.json.DomainObjectReader.getJacksonProperties(DomainObjectReader.java:254) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.json.DomainObjectReader.doMerge(DomainObjectReader.java:158) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.json.DomainObjectReader.doMergeNestedMap(DomainObjectReader.java:238) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.json.DomainObjectReader.doMerge(DomainObjectReader.java:196) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.json.DomainObjectReader.merge(DomainObjectReader.java:136) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] ... 55 common frames omitted {code}

    Spring JIRA | 1 year ago | Justin Lewis Salmon
    org.springframework.http.converter.HttpMessageNotReadableException: Could not read an object of type class demo.Ticket from the request!; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Could not read payload!; nested exception is java.lang.NullPointerException
  2. 0

    I'm not sure if this is a regression, but it is basically the same issue as [DATAREST-491|https://jira.spring.io/browse/DATAREST-491] and [DATAREST-605|https://jira.spring.io/browse/DATAREST-605]. I'm seeing this using spring-boot-starter-data-rest:1.3.0.M5. Check out the [demo project|https://github.com/jlsalmon/mongo_data_rest] and do the following to reproduce: Create a resource: {code} curl -v -X POST http://localhost:8080/tickets -H "Content-Type: application/json" -d '{"properties" : {"a": "1", "b": {"c": "2"}}}' {code} Try to update the properties of the resource via PUT: {code} curl -v -X PUT http://localhost:8080/tickets/5640c0b6b760828633d03cca -H "Content-Type: application/json" -d '{"properties" : {"a": "3", "b": {"c": "4"}}}' {code} The following NPE is observed: {code} org.springframework.http.converter.HttpMessageNotReadableException: Could not read an object of type class demo.Ticket 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.readPutForUpdate(PersistentEntityResourceHandlerMethodArgumentResolver.java:206) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] ... at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.28.jar:8.0.28] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25] 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.merge(DomainObjectReader.java:138) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.json.DomainObjectReader.readPut(DomainObjectReader.java:130) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.config.JsonPatchHandler.applyPut(JsonPatchHandler.java:134) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.readPutForUpdate(PersistentEntityResourceHandlerMethodArgumentResolver.java:203) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] ... 52 common frames omitted Caused by: java.lang.NullPointerException: null at org.springframework.data.rest.webmvc.json.DomainObjectReader.getJacksonProperties(DomainObjectReader.java:254) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.json.DomainObjectReader.doMerge(DomainObjectReader.java:158) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.json.DomainObjectReader.doMergeNestedMap(DomainObjectReader.java:238) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.json.DomainObjectReader.doMerge(DomainObjectReader.java:196) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] at org.springframework.data.rest.webmvc.json.DomainObjectReader.merge(DomainObjectReader.java:136) ~[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na] ... 55 common frames omitted {code}

    Spring JIRA | 1 year ago | Justin Lewis Salmon
    org.springframework.http.converter.HttpMessageNotReadableException: Could not read an object of type class demo.Ticket from the request!; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Could not read payload!; nested exception is java.lang.NullPointerException

    Root Cause Analysis

    1. org.springframework.http.converter.HttpMessageNotReadableException

      Could not read an object of type class demo.Ticket 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.readPutForUpdate()
    2. Spring Data REST - WebMVC
      PersistentEntityResourceHandlerMethodArgumentResolver.readPutForUpdate
      1. org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.readPutForUpdate(PersistentEntityResourceHandlerMethodArgumentResolver.java:206)[spring-data-rest-webmvc-2.4.0.RELEASE.jar:na]
      1 frame