-
Notifications
You must be signed in to change notification settings - Fork 65
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
StackOverflow when serializing object of complicated generic type #98
Comments
Hi Baogang, Thanks for reporting this and taking the time to build a test project.
However if we exclude methods using GensonBuilder (your commented code) the serialization doesn't fail with an error. The resulting JSON I get looks like this
when we try to deserialize this json back, then it fails with the following error Do you have the same results as me or are you encountering another error? I didn't get any stackoverflow. |
Hi Eugen, I did not meet the exception as you. And, if I use gradle-build-result-of-testgenson.txt The version of JDK and gradle on my computer is as below. And, file ` .
` If I uncomment line For the issue |
Yes we can definitely use this or just directly sun.misc.unsafe to generate a no arg constructor. But this would require a bit of work. I am not sure that in your case you want to serialize this object "deeply" like this. Perhaps you should just use a custom converter for that type?
|
Yeah, in most cases a custom converter is good especially for implementing JSON REST API. I just want to test the extreme capability of genson in case that maybe in the future I want to persist some kinds of data into NoSQL db with JSON format . |
As it is now there are two major things that you won't be able to do with genson: serialize objects with cyclic references in them (this is probably what happened in the original scenario with the stackoverflow error) and deserialize classes that don't have a no arg constructor or no constructor that matches with the property names. Both are new features that I would like to add to Genson or even better see them being contributed as a pull request. |
Dear Sir,
There is StackOverflow when genson serialize object of complicated generic type. The complete project for test cases is at https://github.com/kerler/testgenson.
In testgenson project, the test case source code is in https://github.com/kerler/testgenson/tree/master/src/test/java/org/testgenson/GensonGenericTest.java.
StackOverflow occurs when genson serialize object of class
org.openehr.rm.datatypes.quantity.datetime.DvDateTime
.DvDateTime
is in jar/testlibs/openehr-rm-core-1.0.5-SNAPSHOT.jar
in testgenson project, and its source code is in sub projectopenehr-rm-core
of https://github.com/openEHR/java-libs, i.g. https://github.com/openEHR/java-libs/blob/master/openehr-rm-core/src/main/java/org/openehr/rm/datatypes/quantity/datetime/DvDateTime.javaBy setting a breakpoint in IDE, StackOverflow can be seen at line 29
throw couldNotSerialize(th)
incom.owlike.genson.reflect.PropertyAccessor.java::serialize(...)
, where 'th' is:Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate java.lang.StackOverflowError.toString()
.Thanks,
Baogang
The text was updated successfully, but these errors were encountered: