parsing - Play Framework - JSON Serialization Cyclic References (e.g. Files->User, User->Files) --> Stackoverflow -


I am playing with game structure for a few days, but come to an issue that I can not solve You have some "user" and "file" classes. Both give context to each other and are maintained in the database with EBN (@ManyToOne, @OneToMany). Now when the user comes back as a JSON, I get a stack overflow error. Is this a bug in the game or am I missing something?

@ Entity public class file model {Private constant final long serial VERSIONUID = 1L; @ID @ Generated Values ​​Public Long ID; @ManyToOne (cascade = CascadeType.ALL) public user author; }
  @Entity Public Class User Model {Private Stable Last Long Serialvarsion UID = 1L; @ID @ Generated Values ​​Public Long ID; @OneToMany (Mapped = "Author", Cascade = Cascade Type. ALL) Public List & lt; File & gt; Files; }  

  import play.libs.Json; Public category user controls {public static results getJSON ()} {list & lt; Users & gt; User = new model.funder & lt; String, user & gt; (String class, user.class) .all (); Return is OK (Jason. Tojson (user)); A}}  

Staktrres:

  org.codehaus.jackson.map.JsonMappingException: eternal recurrence (stack Ovrfloarr) (reference series By: Model User ["File"] -> com.avaje.ebean.common.BeanList [0] -> Model.phlet ["Author"] -> Model User ["Files"] -> com.avaje Ebean.common.BeanList [0] -> Model.file ["Author"] -> Model User ["Files"] -> com.avaje.ebean.common .BeanList [0] -> Model File ["Author"] - & gt; Model User ["Files"] - & gt; com.avaje.ebean.common.BeanList [0] - & gt; Model. File ["LE A "] -> Model.user [" file "] -> com.avaje.ebean.common.BeanList [0] -> Model.phile [" Author "] -> Model User ["Files"] - & gt; com.avaje.ebean Normal.Binlist [0] -> Model.file ["Author"] -> Model User ["Files"] - & gt; com. avaje.ebean.common.BeanList [0] - & gt; Modlkfail [ "authors"] - & gt; model. users [ "files"] - & gt; com.avaje.ebean.common.BeanList [0] - & gt; Model.file ["author"] - & gt; ... - & gt; Model on Org.codehaus. User ["Files"]) jackson.map.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase.java:164) ~ [Jackson-Mapcart-asl.jar: 1.9.10] org.codehaus.jackson.map.ser.BeanSerializer On .erialize (BeanSerializer.java: 112) ~ [Jackson-map-asl.jar: 1.9.10] org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter.java:446) ~ [Jackson-Mapster- At asl.jar: 1.9 10] org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase.java:150) ~ [Jackson-Nkshakar- on asl.jar: 1.9.10] on org.codehaus.jackson.map.ser. BeanSerializer.serialize (BeanSerializer.java:112) ~ [Jackson-Mapcart-asl.jar: 1.9.10] org.codehaus.jackson.map.ser.std.CollectionSerializer.serializeContents (CollectionSerializer.java:72) ~ [Jackson -mapper-asl.jar: 1.9.10] java.lang.StackOverflowError: null at java.lang.ClassLoader.defineClass1 (Native Method) ~ [na: 1.7.0_45] at java.lang.ClassLoader.defineClass (ClassLoader. java: 800) ~ [na: 1.7.0_45] Girl java.security.SecureClassLoader.defineC (SecureClassLoader.java:142) ~ [na: 1.7.0_45] java.net.URLClassLoader.defineClass (URLClassLoader.java:449) at ~ [na: 1.7.0_45] java.net.URLClassLoader.access $ 100 (.java on URLClassLoader: 71) ~ [na: 1.7.0_45] java.net.URLClassLoader at $ 1.run (URLClassLoader.java:361 ) ~ [Na: 1.7.0_45]  

OK, a few hours of googling After the issues I found the solution: a comment @ Jesninjoror (Import org.codehaus.jackson.annotate.JsonIgnore) which tells JSON method to avoid this is

Edit: Forward During the JSON serialization, Mining is required to write custom D- and serializer to deal with cyclical references. A great post of Steve Hill can be found here:


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -