-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
cbb8b5f
commit 810b240
Showing
2 changed files
with
60 additions
and
1 deletion.
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
59 changes: 59 additions & 0 deletions
59
core/src/test/java/com/alibaba/fastjson2/issues_2600/Issue2662.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,59 @@ | ||
package com.alibaba.fastjson2.issues_2600; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONWriter; | ||
import com.alibaba.fastjson2.annotation.JSONType; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue2662 { | ||
@Test | ||
public void test() { | ||
final WrapperClassA wrapperClassA = new WrapperClassA(); | ||
final PojoClassC pojoClassC = new PojoClassC(); | ||
pojoClassC.setInt1(1); | ||
pojoClassC.setStr2("str"); | ||
wrapperClassA.setPojo(pojoClassC); | ||
final String jsonStr = JSON.toJSONString(wrapperClassA); | ||
assertEquals("{\"pojo\":{\"@type\":\"com.alibaba.fastjson2.issues_2600.Issue2662$PojoClassC\",\"int1\":1,\"str2\":\"str\"}}", jsonStr); | ||
} | ||
|
||
@JSONType(serializeFeatures = {JSONWriter.Feature.WriteClassName, JSONWriter.Feature.NotWriteRootClassName}) | ||
public static class WrapperClassA { | ||
private AbsPojoClassB pojo; | ||
|
||
public AbsPojoClassB getPojo() { | ||
return pojo; | ||
} | ||
|
||
public void setPojo(AbsPojoClassB pojo) { | ||
this.pojo = pojo; | ||
} | ||
} | ||
|
||
public static class AbsPojoClassB { | ||
private Integer int1; | ||
private String str2; | ||
|
||
public Integer getInt1() { | ||
return int1; | ||
} | ||
|
||
public void setInt1(Integer int1) { | ||
this.int1 = int1; | ||
} | ||
|
||
public String getStr2() { | ||
return str2; | ||
} | ||
|
||
public void setStr2(String str2) { | ||
this.str2 = str2; | ||
} | ||
} | ||
|
||
public static class PojoClassC | ||
extends AbsPojoClassB { | ||
} | ||
} |