-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
'尝试修复配置Integer的ToStringSerializer不生效问题'
- Loading branch information
1 parent
77d51b1
commit 0330cab
Showing
2 changed files
with
61 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
54 changes: 54 additions & 0 deletions
54
core/src/test/java/com/alibaba/fastjson2/issues_3100/Issue3157Test.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,54 @@ | ||
package com.alibaba.fastjson2.issues_3100; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.SerializeConfig; | ||
import com.alibaba.fastjson.serializer.SerializerFeature; | ||
import com.alibaba.fastjson.serializer.ToStringSerializer; | ||
import org.junit.Assert; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Issue3157测试类 | ||
* @author changyi.ccy | ||
*/ | ||
public class Issue3157Test { | ||
/** | ||
* 测试: Issue3157 | ||
*/ | ||
@Test | ||
public void testIssue3157() { | ||
SerializeConfig stringSerializeConfig = new SerializeConfig(); | ||
stringSerializeConfig.put(Integer.class, ToStringSerializer.instance); | ||
stringSerializeConfig.put(Long.class, ToStringSerializer.instance); | ||
People people = new People("Test", 10, 10000000L); | ||
String jsonText = "{\"age\":\"10\",\"hairNums\":\"10000000\",\"name\":\"Test\"}"; | ||
Assert.assertEquals("JSON文本不一致", jsonText, JSON.toJSONString(people, stringSerializeConfig, new SerializerFeature[0])); | ||
} | ||
|
||
/** | ||
* People类 | ||
*/ | ||
public static class People { | ||
private String name; | ||
private Integer age; | ||
private Long hairNums; | ||
|
||
public People(String name, Integer age, Long hairNums) { | ||
this.name = name; | ||
this.age = age; | ||
this.hairNums = hairNums; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Integer getAge() { | ||
return age; | ||
} | ||
|
||
public Long getHairNums() { | ||
return hairNums; | ||
} | ||
} | ||
} |