You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The cycle detection introduced in #632 / #645 uses a HashSet, and detects if the object being serialized contains another object that is equal using Object.equals. This reports errors for objects where there isn't actually a cycle, but a contained object tests equal with an enclosing one, like in the following example.
Using IdentityHashMap instead of HashSet would detect actual cycles, but avoid reporting the following error.
Exception in thread "main" org.json.JSONException: JavaBean object contains recursively defined member variable of key "foo"
at org.json.JSONObject.recursivelyDefinedObjectException(JSONObject.java:2722)
at org.json.JSONObject.populateMap(JSONObject.java:1558)
at org.json.JSONObject.<init>(JSONObject.java:371)
at org.json.JSONObject.wrap(JSONObject.java:2496)
at org.json.JSONObject.populateMap(JSONObject.java:1563)
at org.json.JSONObject.populateMap(JSONObject.java:1529)
at org.json.JSONObject.<init>(JSONObject.java:366)
at Json.main(Json.java:6)
The text was updated successfully, but these errors were encountered:
cushon
added a commit
to cushon/JSON-java
that referenced
this issue
Nov 27, 2021
The cycle detection introduced in #632 / #645 uses a
HashSet
, and detects if the object being serialized contains another object that is equal usingObject.equals
. This reports errors for objects where there isn't actually a cycle, but a contained object tests equal with an enclosing one, like in the following example.Using
IdentityHashMap
instead ofHashSet
would detect actual cycles, but avoid reporting the following error.The text was updated successfully, but these errors were encountered: