julman99 / gson-fire

A java library that adds some very useful features to Gson, like Date serializing to unix timestamp or RFC3339, method (getters) serialization, pre/post processors and many others. Check out the documentation to learn how to use it!
http://gsonfire.io
Other
229 stars 37 forks source link

recurcive deserialisation hooks #30

Closed a-a-davydov closed 6 years ago

a-a-davydov commented 8 years ago

Threre is problem with recursive pre/post deserialization processing.

If I have class:

class Node { int i; Node n; }

and I want deserialize following json: {i:1,n:{i:2,n:{i:3}}}

so post deserialisation hook will be called once

julman99 commented 8 years ago

Thanks for reporting the issue. I just added a test that checks a single level recursion and it seems to work. Can you review the test and check if that is the scenario you are describing?

Test: https://github.com/julman99/gson-fire/blob/master/src/test/java/io/gsonfire/gson/HooksTest.java#L43

a-a-davydov commented 8 years ago

Thanks for reaction Julio.

It seems I don't describe my case correct.

I've made some investigation in my and your code.

So, bug is caused by TypeSelector.

I.E. more detailed my case is

abstract class ANode { int i; int typeId; ANode next; }

class CNode1 extends ANode { //stuff }

class CNode2 extends ANode { //stuff }

And I use type selector to determinate which class to use during deserialisation.

It cause TypeSelectorTypeAdapterFactory added in gson.

As I see in https://github.com/julman99/gson-fire/blob/master/src/main/java/io/gsonfire/gson/TypeSelectorTypeAdapterFactory.java on line 62 and 63, TypeSelectorTypeAdapter make default deserialisation without pre- post- hooks.

a-a-davydov commented 8 years ago

Now is late evening here =). I can send detailed test on sunday, if need.

julman99 commented 8 years ago

Oh yes, the TypeSelector is breaking the hooks, post-serializer and other things in some cases. It is a known issue I am working and will be out within the next 2 weeks.

julman99 commented 8 years ago

Just released version 1.8.0 that contains a fix for this issue. Can you confirm it works for you?

Thanks