forked from alibaba/fastjson2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix deserialize HashMap subclass, for issue alibaba#1686
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/src/test/java/com/alibaba/fastjson2/issues_1600/Issue1686.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.alibaba.fastjson2.issues_1600; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.HashMap; | ||
|
||
public class Issue1686 { | ||
@Test | ||
public void test_nest_map_subclass() { | ||
A a = new A(); | ||
a.put("a", new B()); | ||
a.get("a").put("b", "1"); | ||
|
||
String jsonString = JSON.toJSONString(a); | ||
assert jsonString.equals("{\"a\":{\"b\":\"1\"}}"); | ||
|
||
A a1 = JSON.parseObject(jsonString, A.class); | ||
// java.lang.ClassCastException: com.alibaba.fastjson2.JSONObject cannot be cast to B | ||
assert a1.get("a").get("b").equals("1"); | ||
} | ||
|
||
public static class A | ||
extends HashMap<String, B> { | ||
} | ||
|
||
public static class B | ||
extends HashMap<String, String> { | ||
} | ||
} |