Skip to content

Commit

Permalink
add testcase for issue #3104
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Nov 2, 2024
1 parent 179be60 commit 3f33b70
Showing 1 changed file with 31 additions and 0 deletions.
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);
}
}

0 comments on commit 3f33b70

Please sign in to comment.