问题
Im having this error:
com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException: Direct self-reference leading to cycle
I have been trying to avoid the field causing this to be serialized but the error is not corrected. I have tried to put @JsonIgnore everywhere, in the getter, the setter, the attribute and every possible combination of those.
Thanks
-> Edit
I can't import com.google.appengine.repackaged.org.codehaus.jackson.annotate.JsonIgnoreProperties, it says that "Use of com.google.appengine.repackaged may result in your app breaking without warning.". So I import org.codehaus.jackson.annotate.JsonIgnoreProperties instead.
The exception is thrown in the repackaged package (the one I cant import). Is that why my JsonIgnore is not working??
Thanks again.
回答1:
I found the solution. I put the entire package in the annotation.
@com.google.appengine.repackaged.org.codehaus.jackson.annotate.JsonIgnoreProperties({"users"})
public class MyClass extends MySuperClass{
....
}
This way Eclipse doesn't gives me this error: Use of com.google.appengine.repackaged may result in your app breaking without warning and everything worked fine.
回答2:
use @JsonIgnoreProperties({"", comma seperated fields to be ignored on serialization}). Reference
回答3:
Using com.google.appengine.repackaged is usually a very bad idea, because the warning is not there to be ignored or worked around. Instead you should use org.codehaus.jackson.annotate.JsonIgnoreProperties class coming from jackson-core-asl-.jar.
If you are using maven, you can add this library with
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
Otherwise, download it from there http://mavenhub.com/c/org/codehaus/jackson/annotate/JsonIgnoreProperties/jar
When you need a class which is a repackaged import, simply copy the import without the repackaged part (e.g in this case org.codehaus.jackson.annotate.JsonIgnoreProperties) and put it in google. You will find the correct jar you need to add to your build path to have that class available.
来源:https://stackoverflow.com/questions/19552590/appengine-endpoints-jsonmappingexception-avoid-field-to-be-serialized