-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix WriteNulls causing values to be serialized as null, for issue #3049
- Loading branch information
Showing
6 changed files
with
98 additions
and
16 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
13 changes: 13 additions & 0 deletions
13
core/src/test/java/com/alibaba/fastjson2/issues_3000/issue3049/DoubleClazz.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,13 @@ | ||
package com.alibaba.fastjson2.issues_3000.issue3049; | ||
|
||
import com.alibaba.fastjson2.JSONWriter; | ||
import com.alibaba.fastjson2.annotation.JSONField; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class DoubleClazz { | ||
@JSONField(serializeFeatures = JSONWriter.Feature.WriteNulls) | ||
private Double d; | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/test/java/com/alibaba/fastjson2/issues_3000/issue3049/DoubleClazz2.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,10 @@ | ||
package com.alibaba.fastjson2.issues_3000.issue3049; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class DoubleClazz2 { | ||
private Double d; | ||
} |
44 changes: 44 additions & 0 deletions
44
core/src/test/java/com/alibaba/fastjson2/issues_3000/issue3049/Issue3049.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_3000.issue3049; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.Test; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
|
||
/** | ||
* @author 张治保 | ||
* @since 2024/10/8 | ||
*/ | ||
public class Issue3049 { | ||
@Test | ||
@SneakyThrows | ||
void testDouble() { | ||
DoubleClazz c = new DoubleClazz(); | ||
c.setD(1D); | ||
JSONAssert.assertEquals("{\"d\":1.0}", JSON.toJSONString(c), true); | ||
c.setD(null); | ||
JSONAssert.assertEquals("{\"d\":null}", JSON.toJSONString(c), true); | ||
|
||
DoubleClazz2 c2 = new DoubleClazz2(); | ||
c2.setD(1D); | ||
JSONAssert.assertEquals("{\"d\":1.0}", JSON.toJSONString(c2), true); | ||
c2.setD(null); | ||
JSONAssert.assertEquals("{}", JSON.toJSONString(c2), true); | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
void testLong() { | ||
LongClazz c = new LongClazz(); | ||
c.setD(1L); | ||
JSONAssert.assertEquals("{\"d\":1.0}", JSON.toJSONString(c), true); | ||
c.setD(null); | ||
JSONAssert.assertEquals("{\"d\":null}", JSON.toJSONString(c), true); | ||
|
||
LongClazz2 c2 = new LongClazz2(); | ||
c2.setD(1L); | ||
JSONAssert.assertEquals("{\"d\":1.0}", JSON.toJSONString(c2), true); | ||
c2.setD(null); | ||
JSONAssert.assertEquals("{}", JSON.toJSONString(c2), true); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
core/src/test/java/com/alibaba/fastjson2/issues_3000/issue3049/LongClazz.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,13 @@ | ||
package com.alibaba.fastjson2.issues_3000.issue3049; | ||
|
||
import com.alibaba.fastjson2.JSONWriter; | ||
import com.alibaba.fastjson2.annotation.JSONField; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class LongClazz { | ||
@JSONField(serializeFeatures = JSONWriter.Feature.WriteNulls) | ||
private Long d; | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/test/java/com/alibaba/fastjson2/issues_3000/issue3049/LongClazz2.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,10 @@ | ||
package com.alibaba.fastjson2.issues_3000.issue3049; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class LongClazz2 { | ||
private Long d; | ||
} |