-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Milestone
Description
When a bean has a big-d Double, and the value is null, it gets decoded as 0.0 instead. The two are not equivalent.
This code shows the problem:
package test;
import com.fasterxml.jackson.jr.ob.JSON;
import java.util.List;
public class DoubleTest {
private Double value;
public static void main(String[] args) throws Exception {
for (var testInput: List.of(
"{\"value\": 1.0}", "{\"value\": 0.0}", "{}", "{\"value\": null}")) {
System.out.println("Input JSON: " + testInput + " - Output bean: " + JSON.std.beanFrom(DoubleTest.class, testInput));
}
}
public Double getValue() {
return value;
}
public void setValue(Double value) {
this.value = value;
}
public @Override String toString() {
return "DoubleTest[" + value + "]";
}
}
Output:
Input JSON: {"value": 1.0} - Output bean: DoubleTest[1.0]
Input JSON: {"value": 0.0} - Output bean: DoubleTest[0.0]
Input JSON: {} - Output bean: DoubleTest[null]
Input JSON: {"value": null} - Output bean: DoubleTest[0.0]
The fourth JSON object should be deserialized the same as the third.
MikeDombo, vic-caopengfei and Serob
Metadata
Metadata
Assignees
Labels
No labels