org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"])

Spring JIRA | Johannes Hiemer | 2 years ago
  1. 0

    My setup is completely based on Java Configuration files. I configured my my application as follows: {code:java} @Override protected Class<?>[] getRootConfigClasses() { return new Class<?>[] { CustomMongoDBRepositoryConfig.class, CustomJPARepositoryConfig.class, CustomSecurityConfiguration.class }; } .. @Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext(); webCtx.register(CustomRepositoryRestMvcConfiguration.class); DispatcherServlet dispatcherServlet = new DispatcherServlet(webCtx); ServletRegistration.Dynamic appServlet = servletContext.addServlet("exporter", dispatcherServlet); appServlet.setAsyncSupported(true); appServlet.setLoadOnStartup(1); appServlet.addMapping("/*"); FilterRegistration.Dynamic corsFilter = servletContext.addFilter("corsFilter", CORSFilter.class); corsFilter.addMappingForUrlPatterns(null, false, "/*"); FilterRegistration.Dynamic filter = servletContext.addFilter("openSessionInViewFilter", OpenEntityManagerInViewFilter.class); filter.setInitParameter("singleSession", "true"); filter.addMappingForServletNames(null, true, "exporter"); FilterRegistration.Dynamic securityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")); securityFilter.addMappingForUrlPatterns(null, false, "/*"); super.onStartup(servletContext); } {code} The interesting thing is, everything is working fine. MVC URLs are mapped, controllers are working, Spring Security is working, SD REST URLs are mapped and working, but one thing is not working: POST/PUT of entities with rels. Having the following payload posted to /roles {code:json} { "name": "Developer", "description": "Standard role for a agent developer in the system", "rights": [ "http://localhost:8080/web/rights/186", "http://localhost:8080/web/rights/189", "http://localhost:8080/web/rights/185", "http://localhost:8080/web/rights/46" ] } {code} leads to the following exception: {code} LOGBACK:16:54:09.765 [tomcat-http--2] ERROR o.s.d.r.w.RepositoryRestExceptionHandler - Could not read JSON: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]) org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]) at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:208) ~[AbstractJackson2HttpMessageConverter.class:4.1.1.RELEASE] at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readInternal(AbstractJackson2HttpMessageConverter.java:192) ~[AbstractJackson2HttpMessageConverter.class:4.1.1.RELEASE] at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:159) ~[AbstractHttpMessageConverter.class:4.1.1.RELEASE] at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.read(PersistentEntityResourceHandlerMethodArgumentResolver.java:185) ~[PersistentEntityResourceHandlerMethodArgumentResolver.class:na] at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.read(PersistentEntityResourceHandlerMethodArgumentResolver.java:168) ~[PersistentEntityResourceHandlerMethodArgumentResolver.class:na] at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.resolveArgument(PersistentEntityResourceHandlerMethodArgumentResolver.java:123) ~[PersistentEntityResourceHandlerMethodArgumentResolver.class:na] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77) ~[HandlerMethodArgumentResolverComposite.class:4.1.1.RELEASE] {code} Which in turn is a result of fact that in DomainClassConverter the variable repositories is empty during the POST/PUT call. Following that the RepositoryInformations are empty and the NPE is thrown. I guess this is happening due to some context splitup during startup time. The interesting thing is, that POST/PUT a plain object without any rels works properly, I am not able to see any stuff in the debug logs showing me the second context

    Spring JIRA | 2 years ago | Johannes Hiemer
    org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"])
  2. 0

    My setup is completely based on Java Configuration files. I configured my my application as follows: {code:java} @Override protected Class<?>[] getRootConfigClasses() { return new Class<?>[] { CustomMongoDBRepositoryConfig.class, CustomJPARepositoryConfig.class, CustomSecurityConfiguration.class }; } .. @Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext(); webCtx.register(CustomRepositoryRestMvcConfiguration.class); DispatcherServlet dispatcherServlet = new DispatcherServlet(webCtx); ServletRegistration.Dynamic appServlet = servletContext.addServlet("exporter", dispatcherServlet); appServlet.setAsyncSupported(true); appServlet.setLoadOnStartup(1); appServlet.addMapping("/*"); FilterRegistration.Dynamic corsFilter = servletContext.addFilter("corsFilter", CORSFilter.class); corsFilter.addMappingForUrlPatterns(null, false, "/*"); FilterRegistration.Dynamic filter = servletContext.addFilter("openSessionInViewFilter", OpenEntityManagerInViewFilter.class); filter.setInitParameter("singleSession", "true"); filter.addMappingForServletNames(null, true, "exporter"); FilterRegistration.Dynamic securityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")); securityFilter.addMappingForUrlPatterns(null, false, "/*"); super.onStartup(servletContext); } {code} The interesting thing is, everything is working fine. MVC URLs are mapped, controllers are working, Spring Security is working, SD REST URLs are mapped and working, but one thing is not working: POST/PUT of entities with rels. Having the following payload posted to /roles {code:json} { "name": "Developer", "description": "Standard role for a agent developer in the system", "rights": [ "http://localhost:8080/web/rights/186", "http://localhost:8080/web/rights/189", "http://localhost:8080/web/rights/185", "http://localhost:8080/web/rights/46" ] } {code} leads to the following exception: {code} LOGBACK:16:54:09.765 [tomcat-http--2] ERROR o.s.d.r.w.RepositoryRestExceptionHandler - Could not read JSON: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]) org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]) at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:208) ~[AbstractJackson2HttpMessageConverter.class:4.1.1.RELEASE] at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readInternal(AbstractJackson2HttpMessageConverter.java:192) ~[AbstractJackson2HttpMessageConverter.class:4.1.1.RELEASE] at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:159) ~[AbstractHttpMessageConverter.class:4.1.1.RELEASE] at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.read(PersistentEntityResourceHandlerMethodArgumentResolver.java:185) ~[PersistentEntityResourceHandlerMethodArgumentResolver.class:na] at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.read(PersistentEntityResourceHandlerMethodArgumentResolver.java:168) ~[PersistentEntityResourceHandlerMethodArgumentResolver.class:na] at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.resolveArgument(PersistentEntityResourceHandlerMethodArgumentResolver.java:123) ~[PersistentEntityResourceHandlerMethodArgumentResolver.class:na] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77) ~[HandlerMethodArgumentResolverComposite.class:4.1.1.RELEASE] {code} Which in turn is a result of fact that in DomainClassConverter the variable repositories is empty during the POST/PUT call. Following that the RepositoryInformations are empty and the NPE is thrown. I guess this is happening due to some context splitup during startup time. The interesting thing is, that POST/PUT a plain object without any rels works properly, I am not able to see any stuff in the debug logs showing me the second context

    Spring JIRA | 2 years ago | Johannes Hiemer
    org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"])
  3. 0

    Spring Data REST - POST new entity with relationships

    Stack Overflow | 3 years ago | pakman
    org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: (was java.lang.NullPointerException) (through reference chain: Address["person"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: Address["person"])
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    GitHub comment 1#238048746

    GitHub | 4 months ago | Pytry
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: N/A (through reference chain: com.dogjaw.services.authentication.b2c.AzurePolicyMetaData["http_logout_supported"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: N/A (through reference chain: com.dogjaw.services.authentication.b2c.AzurePolicyMetaData["http_logout_supported"])
  6. 0

    dynamic json response: Could not read JSON: N/A (through reference chain) jackson fasterxml

    Stack Overflow | 2 years ago | Sven Deckers
    org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: N/A (through reference chain: be.kava.farma.modules.prins.ImageListingResponse["123465"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: N/A (through reference chain: be.kava.farma.modules.prins.ImageListingResponse["123456"])

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.springframework.http.converter.HttpMessageNotReadableException

      Could not read JSON: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: de.cloudscale.model.user.Role["rights"])

      at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType()
    2. Spring
      AbstractHttpMessageConverter.read
      1. org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:208)[AbstractJackson2HttpMessageConverter.class:4.1.1.RELEASE]
      2. org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readInternal(AbstractJackson2HttpMessageConverter.java:192)[AbstractJackson2HttpMessageConverter.class:4.1.1.RELEASE]
      3. org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:159)[AbstractHttpMessageConverter.class:4.1.1.RELEASE]
      3 frames
    3. Spring Data REST - WebMVC
      PersistentEntityResourceHandlerMethodArgumentResolver.resolveArgument
      1. org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.read(PersistentEntityResourceHandlerMethodArgumentResolver.java:185)[PersistentEntityResourceHandlerMethodArgumentResolver.class:na]
      2. org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.read(PersistentEntityResourceHandlerMethodArgumentResolver.java:168)[PersistentEntityResourceHandlerMethodArgumentResolver.class:na]
      3. org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.resolveArgument(PersistentEntityResourceHandlerMethodArgumentResolver.java:123)[PersistentEntityResourceHandlerMethodArgumentResolver.class:na]
      3 frames
    4. Spring
      HandlerMethodArgumentResolverComposite.resolveArgument
      1. org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)[HandlerMethodArgumentResolverComposite.class:4.1.1.RELEASE]
      1 frame