1

杰克逊是否处理/抛出像net.sf.json.JSONException 这样的循环异常:层次结构中有一个循环!当它检测到要在 json 中转换的 java 对象中的循环时,在 json-lib 中抛出。如果是这样,我们该如何处理。

json-lib 中抛出的错误如下

    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)

提前致谢。

4

2 回答 2

1

你想要@JsonBackReference@JsonManagedReference

于 2012-02-02T15:53:05.337 回答
0

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.

于 2012-02-02T16:23:21.983 回答