-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix writeDouble and writeFloat of JSONWriter when value Not a Number …
…, for issue #1562
- Loading branch information
1 parent
688579d
commit 8876c08
Showing
2 changed files
with
52 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
44 changes: 44 additions & 0 deletions
44
core/src/test/java/com/alibaba/fastjson2/issues_1500/Issue1562.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,44 @@ | ||
package com.alibaba.fastjson2.issues_1500; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.annotation.JSONField; | ||
import lombok.Data; | ||
import org.junit.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class Issue1562 { | ||
@Test | ||
public void test() { | ||
String expected = "{\"value\":null,\"value10\":null,\"value11\":null,\"value12\":null,\"value2\":null,\"value3\":null,\"value4\":null,\"value5\":null,\"value6\":null,\"value7\":null,\"value8\":null,\"value9\":null}"; | ||
assertEquals(expected, JSON.toJSONString(new Cs())); | ||
} | ||
|
||
@Data | ||
class Cs { | ||
@JSONField(format = "#.##") | ||
private double value = Double.NaN; | ||
@JSONField(format = "#.##") | ||
private float value2 = Float.NaN; | ||
@JSONField(format = "#.##") | ||
private double value3 = Double.NEGATIVE_INFINITY; | ||
@JSONField(format = "#.##") | ||
private float value4 = Float.NEGATIVE_INFINITY; | ||
@JSONField(format = "#.##") | ||
private double value5 = Double.POSITIVE_INFINITY; | ||
@JSONField(format = "#.##") | ||
private float value6 = Float.POSITIVE_INFINITY; | ||
@JSONField | ||
private double value7 = Double.NaN; | ||
@JSONField | ||
private float value8 = Float.NaN; | ||
@JSONField | ||
private double value9 = Double.NEGATIVE_INFINITY; | ||
@JSONField | ||
private float value10 = Float.NEGATIVE_INFINITY; | ||
@JSONField | ||
private double value11 = Double.POSITIVE_INFINITY; | ||
@JSONField | ||
private float value12 = Float.POSITIVE_INFINITY; | ||
} | ||
} |