-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix writeClassName not work on JSONField.serializeFeatures, for issue #…
- Loading branch information
Showing
2 changed files
with
64 additions
and
4 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
58 changes: 58 additions & 0 deletions
58
core/src/test/java/com/alibaba/fastjson2/issues_1900/Issue1947.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,58 @@ | ||
package com.alibaba.fastjson2.issues_1900; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONWriter; | ||
import com.alibaba.fastjson2.annotation.JSONField; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue1947 { | ||
@Test | ||
public void test() { | ||
A a = new A(); | ||
a.id = 1; | ||
a.name = "a"; | ||
|
||
B b = new B(); | ||
b.id = 2; | ||
|
||
C c = new C(); | ||
c.list = new ID[]{a, b}; | ||
|
||
String str = JSON.toJSONString(c); | ||
assertEquals( | ||
"{\"list\":[{\"@type\":\"" + Issue1947.class.getName() + "$A\",\"id\":1,\"name\":\"a\"},{\"@type\":\"com.alibaba.fastjson2.issues_1900.Issue1947$B\",\"id\":2}]}", | ||
str); | ||
} | ||
|
||
public static class C { | ||
@JSONField(serializeFeatures = JSONWriter.Feature.WriteClassName) | ||
public ID[] list; | ||
} | ||
|
||
public static class A | ||
implements ID { | ||
public int id; | ||
public String name; | ||
|
||
@Override | ||
public int getId() { | ||
return id; | ||
} | ||
} | ||
|
||
public static class B | ||
implements ID { | ||
public int id; | ||
|
||
@Override | ||
public int getId() { | ||
return id; | ||
} | ||
} | ||
|
||
public interface ID { | ||
int getId(); | ||
} | ||
} |