-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix inconsistent behaviour when enable WriteClasName, for issue #2981
- Loading branch information
1 parent
e6ff30a
commit 48d4987
Showing
2 changed files
with
31 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
28 changes: 28 additions & 0 deletions
28
core/src/test/java/com/alibaba/fastjson2/issues_2900/Issue2981.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,28 @@ | ||
package com.alibaba.fastjson2.issues_2900; | ||
|
||
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 Issue2981 { | ||
@Test | ||
public void test() { | ||
Shape.Circle circle = new Shape.Circle(); | ||
circle.setRadius(5); | ||
assertEquals(JSON.parse(JSON.toJSONString(circle)), JSON.toJSON(circle)); | ||
} | ||
|
||
@JSONType(typeKey = "type", seeAlso = {Shape.Circle.class}) | ||
public static class Shape { | ||
@JSONType(typeKey = "type", typeName = "circle", serializeFeatures = JSONWriter.Feature.WriteClassName) | ||
public static class Circle | ||
extends Shape { | ||
private int radius; | ||
public int getRadius() { return radius; } | ||
public void setRadius(int radius) { this.radius = radius; } | ||
} | ||
} | ||
} |