-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
test-jdk17/src/test/java/com/alibaba/fastjson2/issues/Issue3104.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,31 @@ | ||
package com.alibaba.fastjson2.issues; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.annotation.JSONCreator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue3104 { | ||
record Transform(Bridge bridge) { | ||
public Transform(String from, String to) { | ||
this(new Bridge(from, to)); | ||
} | ||
|
||
@JSONCreator | ||
public Transform(Bridge bridge) { | ||
this.bridge = bridge; | ||
} | ||
} | ||
|
||
record Bridge(String from, String to) { | ||
} | ||
|
||
@Test | ||
public void test() { | ||
String json = JSON.toJSONString(new Transform("zhangsan", "lisi")); | ||
assertEquals("{\"bridge\":{\"from\":\"zhangsan\",\"to\":\"lisi\"}}", json); | ||
Transform transform = JSON.parseObject(json, Transform.class); | ||
System.out.println(transform); | ||
} | ||
} |