forked from alibaba/fastjson2
-
Notifications
You must be signed in to change notification settings - Fork 0
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
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
fastjson1-compatible/src/test/java/com/alibaba/fastjson/v2issues/Issue3157.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,48 @@ | ||
package com.alibaba.fastjson.v2issues; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.alibaba.fastjson.serializer.SerializeConfig; | ||
import com.alibaba.fastjson.serializer.ToStringSerializer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue3157 { | ||
public static class People { | ||
private Integer age; | ||
|
||
private Long hairNums; | ||
|
||
private String name; | ||
|
||
public People(Integer age, String name, Long hairNums) { | ||
this.age = age; | ||
this.name = name; | ||
this.hairNums = hairNums; | ||
} | ||
|
||
public Integer getAge() { | ||
return age; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Long getHairNums() { | ||
return hairNums; | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
SerializeConfig stringSerializeConfig = new SerializeConfig(); | ||
stringSerializeConfig.put(Integer.class, ToStringSerializer.instance); | ||
stringSerializeConfig.put(Long.class, ToStringSerializer.instance); | ||
|
||
People one = new People(10, "aaa", 10000000L); | ||
assertEquals( | ||
"{\"age\":\"10\",\"hairNums\":\"10000000\",\"name\":\"aaa\"}", | ||
JSON.toJSONString(one, stringSerializeConfig)); | ||
} | ||
} |