-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Problem with JavaType.toString()
for recursive (self-referential) types
#1301
Comments
Hmmh. This is tricky because it is truly recursive definition, and there is no clean way to keep track of reference track during |
JavaType.toString()
for recursive (self-referential) types
Thank you again -- I was able to fix it relatively easily since this affects self-referential |
Also: for what that is worth, test fails on 2.6, but for other reasons; recursive type resolution itself fails. |
Hello, I am using jackson-databind 2.8.8, and have a class with a similar definition (extending a Map, where the values are are of the type of the same class). It seems like I am still facing this exact recursion issue. Here's the definition of the class: public class Tree<T> extends HashMap<T, Tree<T>> implements Serializable {
....
} Now, when executing the following code: ObjectMapper om = new ObjectMapper();
final TypeResolverBuilder<?> typer = new StdTypeResolverBuilder()
.init(JsonTypeInfo.Id.CLASS, null)
.inclusion(JsonTypeInfo.As.PROPERTY)
.typeProperty(GraphSONTokens.CLASS);
om.setDefaultTyping(typer);
String res = om.writeValueAsString(t);
Object tRead = om.readValue(res, Tree.class);
System.out.println("tRead = " + tRead); When calling
Looking briefly into the code, it seems like because of the recursive definition of the class, the equals call in |
@newkek Could you please file a new issue, copying information you provided? I need a reproduction and see if and how to prevent infinite recursion. It is possible this is regression due to other changes/fixes needed to support usage of self-recursive type references. |
Thanks - will do right away. |
New issue: #1658. |
@ALL - How to solve this issue ? Does any knows the solution ? |
I'm getting a StackOverflowError when I try to use this class with Jackson:
Here's a snippet of the stack trace I get:
I did some debugging and found that this looks like the location where the stack track starts:
It's line 87 in StdValueInstantiator. That looks like it is calling toString() on the on the type and then it goes into an infinite recursion state. I'm not sure why the toString() call is necessary, but it seems like all of this is for debugging and errors and pre-calculating the string is preventing Jackson from working at all even if there isn't an error.
WORK-AROUND: In case anyone looks at this issue and needs a work around, you can use the @JsonAnySetter to fix this issue. Here's the code:
I also think that this can likely be fixed with code like this:
com.fasterxml.jackson.databind.type.MapType.java#toString()
The text was updated successfully, but these errors were encountered: