Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

custom JsonSerializer (using @JsonSerialize annotation) causing NullPointerException #48

Closed
jwijgerd opened this issue Jan 6, 2015 · 0 comments

Comments

@jwijgerd
Copy link
Contributor

jwijgerd commented Jan 6, 2015

When a property is annotated with @JsonSerialize the OptimizedBeanPropertyWriter does not copy the serializer from the BeanPropertyWriter. This caused both _serializer and _dynamicSerializers fields to be null, leading to the following stacktrace:

com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: org.elasticsoftware.elasticactors.base.serialization.TestObjectWIthJsonSerialize["amount"])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:210)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:177)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:187)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:647)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:128)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:2881)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2338)
at org.elasticsoftware.elasticactors.base.serialization.ObjectMapperBuilderTest.testAfterburnerModule(ObjectMapperBuilderTest.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:609)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:532)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:686)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1018)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.runWorkers(TestRunner.java:759)
at org.testng.TestRunner.privateRun(TestRunner.java:592)
at org.testng.TestRunner.run(TestRunner.java:486)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:327)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
at org.testng.SuiteRunner.run(SuiteRunner.java:204)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:912)
at org.testng.TestNG.runSuitesLocally(TestNG.java:876)
at org.testng.TestNG.run(TestNG.java:784)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.NullPointerException
at com.fasterxml.jackson.module.afterburner.ser.ObjectMethodPropertyWriter.serializeAsField(ObjectMethodPropertyWriter.java:58)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:639)
... 32 more

I have a fix for this and will issue a pull request

Kind regards,

Joost

jwijgerd added a commit to jwijgerd/jackson-module-afterburner that referenced this issue Jan 6, 2015
jwijgerd added a commit to jwijgerd/jackson-module-afterburner that referenced this issue Jan 6, 2015
jwijgerd added a commit to jwijgerd/jackson-module-afterburner that referenced this issue Jan 6, 2015
fix for issue FasterXML#48 - reverted pom change of the annotations module version
cowtowncoder added a commit that referenced this issue Jan 7, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant