Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Null pointer exception when serializing object with null field AND while using hooks and type selectors #25
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!
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:
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