java - How to get around circular references when using Gson? -


i building android application, in using gson store object data. have type goal using has following properties:

private long id; private string goalname; private boolean ismaingoal; private goal upperlevelgoal; private goal maingoal; private arraylist<goal> subgoals; private int goallevel; private string textviewsubgoalline; private arraylist<urlcomplex> siteswithingoal; 

when using gson's tojson() method, stackoverflowerror. have read because gson cannot handle circular references -- is, cannot perform tojson() on goal or arraylist<goal> properties.

i understand can somehow use typetoken around issue. (gson.tojson() throws stackoverflowerror) however, have read manual (http://google-gson.googlecode.com/svn/tags/1.1.1/docs/javadocs/com/google/gson/reflect/typetoken.html) , don't understand how can used so.

does know way around using circular references can store info in json via gson?

typetoken won't help, not made that. if want handle circular references in gson, need typeadapterfactory, not simple.

a better approach parse json jackson (but never used functionality) : http://wiki.fasterxml.com/jacksonfeaturebidirreferences


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -