Reputation: 25
Does jackson Handles/throws the Cyclic exception like net.sf.json.JSONException: There is a cycle in the hierarchy! thrown in json-lib when it detects the cycle in java object that is to be converted in json. If so how can we handle it.
Error thrown in json-lib is as follow
1169 SEVERE: Servlet.service() for servlet JSONControllerServletGZIP threw exception
1170 net.sf.json.JSONException: There is a cycle in the hierarchy!
1171 at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsArray(CycleDetectionStra
1172 at net.sf.json.JSONArray._fromCollection(JSONArray.java:749)
1173 at net.sf.json.JSONArray.fromObject(JSONArray.java:165)
1174 at net.sf.json.JSONObject._processValue(JSONObject.java:2132)
1175 at net.sf.json.JSONObject._setInternal(JSONObject.java:2177)
1176 at net.sf.json.JSONObject.setValue(JSONObject.java:1005)
1177 at net.sf.json.JSONObject._fromMap(JSONObject.java:886)
1178 at net.sf.json.JSONObject.fromObject(JSONObject.java:248)
Thanks in advance.
Upvotes: 1
Views: 774
Reputation: 116610
No, Jackson does not keep track of cyclic instances, except for special case of self-reference which is caught. As suggested, currently best way to deal with this is by use of annotations, at least in cases where you have parent/child style reference.
Upvotes: 0