Skip to content

Commit

Permalink
fix JSONObject ClassCastException, for issue #2762
Browse files Browse the repository at this point in the history
  • Loading branch information
Cooper-Zhong authored and wenshao committed Jul 29, 2024
1 parent 41d3a01 commit 46a5d69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public Object get(Object key) {
val = map.get(key.toString());
}

if (val instanceof com.alibaba.fastjson2.JSONObject) {
val = new com.alibaba.fastjson.JSONObject((com.alibaba.fastjson2.JSONObject) val);
}

return val;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.alibaba.fastjson.v2issues;

import com.alibaba.fastjson.JSONObject;
import org.json.JSONException;
import org.junit.jupiter.api.Test;

public class Issue2762 {
@Test
public void test() throws JSONException {
String jsonString = "{\"this0\":{\"$ref\":\"1\"}}";
JSONObject jsonObject = JSONObject.parseObject(jsonString, JSONObject.class);
JSONObject innerObject1 = (JSONObject) jsonObject.get("this0");
}
}

0 comments on commit 46a5d69

Please sign in to comment.