-
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 support FieldBased feature on field for issue #2350
- Loading branch information
1 parent
021facc
commit 652cb53
Showing
3 changed files
with
42 additions
and
0 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
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
36 changes: 36 additions & 0 deletions
36
core/src/test/java/com/alibaba/fastjson2/issues_2300/Issue2350.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,36 @@ | ||
package com.alibaba.fastjson2.issues_2300; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONReader; | ||
import com.alibaba.fastjson2.annotation.JSONField; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
public class Issue2350 { | ||
|
||
@Test | ||
public void test() { | ||
String json = "{\n" + | ||
"\t\"testField\": \"My Test\",\n" + | ||
"\t\"testField2\": \"My Test2\"\n" + | ||
"}"; | ||
TestClass testClass = JSON.parseObject(json, TestClass.class); | ||
assertEquals("My Test", testClass.getTestField()); | ||
assertNull(testClass.getTestField2()); | ||
} | ||
|
||
public static class TestClass { | ||
@JSONField(deserializeFeatures = { JSONReader.Feature.FieldBased }) | ||
private String testField; | ||
private String testField2; | ||
|
||
public String getTestField() { | ||
return testField; | ||
} | ||
public String getTestField2() { | ||
return testField2; | ||
} | ||
} | ||
} |