Skip to content

Commit 39619cd

Browse files
committed
add testcase
1 parent 6bc635c commit 39619cd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

core/src/test/java/com/alibaba/fastjson2/annotation/JSONFieldTest2.java

+26
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,30 @@ public int getId() {
6363
return id;
6464
}
6565
}
66+
67+
@Test
68+
public void test_alternateNames_4() {
69+
VO4 vo = JSON.parseObject("{\"id\":101}", VO4.class);
70+
assertEquals(101, vo.id);
71+
72+
VO4 vo2 = JSON.parseObject("{\"uid\":101}", VO4.class);
73+
assertEquals(101, vo2.id);
74+
}
75+
76+
public static class VO4 {
77+
private int id;
78+
79+
private VO4(int id) {
80+
this.id = id;
81+
}
82+
83+
@JSONCreator
84+
public static VO4 valueOf(@JSONField(name = "id", alternateNames = "uid") int id) {
85+
return new VO4(id);
86+
}
87+
88+
public int getId() {
89+
return id;
90+
}
91+
}
6692
}

0 commit comments

Comments
 (0)