Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null pointer exception when serializing object with null field AND while using hooks and type selectors #25

Closed
knezmilos13 opened this issue Jan 18, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@knezmilos13
Copy link

commented Jan 18, 2016

I've mostly been using GSON and gson-fire for deserialization, and I've had no problems with that. However, I've been having a following problem when trying to serialize data. I've tried using the same GSON instance I use for deseriailzation, and this istance has hooks and a type selector enabled. When trying to serialize object that has a null value in one of his variables (both the object and the null attribute being of types covered by my custom type selector), I get a null pointer exception at HooksInvoker class, line 47. When I disable hooks, I get an exception at TypeSelectorTypeAdapterFactory, line 48. In both cases value/object variables are null when processing reaches the null object which is a part of the object being seriailzed.

I've momentarily solved this by using a different GSON instance for serialization, which doesn't use hooks nor type selection but that might not work for me in the future, and this seems to be a bug of some kind. At the very least, I think that hooks should totaly be ignored if object is null. Probably something similar should be done with the type selection.

Your library was otherwise very helpful to me, and I'm hoping you'll take a look at this. Thanks!

@julman99

This comment has been minimized.

Copy link
Owner

commented Jan 18, 2016

Thanks for this report, I will look into it during this week

@julman99

This comment has been minimized.

Copy link
Owner

commented Feb 4, 2016

Sorry for the delay on my response. Please try version 1.5.1 and let me know if it fixes your problem.

Thanks!

@knezmilos13

This comment has been minimized.

Copy link
Author

commented Feb 23, 2016

Hey, I've changed my code due to some other requirements so this thing stopped being an issue to me, and I forgot to pull your new version. Until today, that is, when I got a similar exception to these previous ones, but while deserializing this time:

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Not a JSON Object: null com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:221) com.google.gson.TypeAdapter.fromJsonTree(TypeAdapter.java:285) io.gsonfire.gson.TypeSelectorTypeAdapterFactory$TypeSelectorTypeAdapter.read(TypeSelectorTypeAdapterFactory.java:60)
...

So I've pulled in your new version just now, and it actually works even in this case - I guess your fix solved a wider array of null-caused problems! Thanks :D

@julman99

This comment has been minimized.

Copy link
Owner

commented Feb 23, 2016

nice! I did fix other potential null pointer exceptions based on your initial report

thanks for helping out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.