spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
921 stars 563 forks source link

NPE in com.fasterxml.jackson.databind.deser.std.StdDeserializer [DATAREST-1147] #1511

Open spring-projects-issues opened 7 years ago

spring-projects-issues commented 7 years ago

Michael Igler opened DATAREST-1147 and commented

When trying to map a response from a GET-request back to a resources-list I am getting a NPE:

@Autowired private BeanFactory beanFactory; ... halObjectMapper = (ObjectMapper) beanFactory.getBean("_halObjectMapper"); halObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); halObjectMapper.enable(SerializationFeature.INDENT_OUTPUT); halObjectMapper.registerModule(new Jackson2HalModule()); halObjectMapper.registerModule(new MrBeanModule()); ... Resources<Resource\> releaseFormats = halObjectMapper .readValue(releaseFormatsResponseBody, halObjectMapper .getTypeFactory() .constructParametricType(Resources.class, halObjectMapper .getTypeFactory() .constructParametricType(Resource.class, ReleaseFormat.class)));

java.lang.NullPointerException at com.fasterxml.jackson.databind.deser.std.StdDeserializer.\(StdDeserializer.java:66) at com.fasterxml.jackson.databind.deser.std.ContainerDeserializerBase.\(ContainerDeserializerBase.java:52) at com.fasterxml.jackson.databind.deser.std.ContainerDeserializerBase.\(ContainerDeserializerBase.java:60) at org.springframework.hateoas.hal.Jackson2HalModule$HalResourcesDeserializer.\(Jackson2HalModule.java:618) at org.springframework.hateoas.hal.Jackson2HalModule$HalResourcesDeserializer.\(Jackson2HalModule.java:613) at org.springframework.hateoas.hal.Jackson2HalModule$HalResourcesDeserializer.createContextual(Jackson2HalModule.java:678) at com.fasterxml.jackson.databind.DeserializationContext.handlePrimaryContextualization(DeserializationContext.java:651) at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.constructSettableProperty(BeanDeserializerFactory.java:848) at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:564) at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:269) at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:179) at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:411) at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:349) at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264) at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244) at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142) at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:477) at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:4179) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3997) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3030) at de.....ReleaseFormatRestTest.testFindReleaseFormats(ReleaseFormatRestTest.java:148) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:200) at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:187) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:212) at org.testng.internal.Invoker.invokeMethod(Invoker.java:707) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) at org.testng.SuiteRunner.runTest(SuiteRunner.java:348) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305) at org.testng.SuiteRunner.run(SuiteRunner.java:254) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) at org.testng.TestNG.run(TestNG.java:1057) at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72) at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)


Affects: 3.0 GA (Kay)

spring-projects-issues commented 7 years ago

Michael Igler commented

I think the cure is in https://github.com/spring-projects/spring-hateoas/blob/master/src/main/java/org/springframework/hateoas/hal/Jackson2HalModule.java Line 612 where

public HalResourcesDeserializer(JavaType vc) { this(TypeFactory.defaultInstance().constructCollectionLikeType(List.class, vc), vc); }

is better than what I have when debugging things:

public HalResourcesDeserializer(JavaType vc) { this(null, vc); }

spring-projects-issues commented 7 years ago

Michael Igler commented

Adding a

0.24.0.BUILD-SNAPSHOT in pom.xml resolves the issue
spring-projects-issues commented 7 years ago

Michael Igler commented

Issue can be closed as 0.24 is released