You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(moved from one reported at old jackson-datatype-jdk8, issue 32)
When deserializing a yaml file if my pojo has OptionalInt rather than Optional, the empty case doesn't seem to be handled right.
Test file:
test:
value:
Test pojo class:
private static class MyTestPojo {
private OptionalInt value = OptionalInt.empty();
public OptionalInt getValue() {
return value;
}
public void setValue(OptionalInt value) {
this.value = value;
}
@Override
public String toString() {
return "MyTestPojo{" +
"value=" + value +
'}';
}
}
And the driving code:
private static final ObjectMapper om = new ObjectMapper(new YAMLFactory()).registerModule(new Jdk8Module());
private static final Path testPath = Paths.get("C:/Development/testYaml.txt");
private static final TypeReference<Map<String, MyTestPojo>> tr = new TypeReference<Map<String, MyTestPojo>>() {
};
public static void main(String... args) throws IOException {
try (BufferedReader br = Files.newBufferedReader(testPath, StandardCharsets.UTF_8)) {
Map<String, Object> read = om.readValue(br, tr);
System.out.println(read);
}
}
When this file is deserialized with this code, I get a response of {test=MyTestPojo{value=OptionalInt[0]}} (as in, it's an optionalint that's present with a value of 0). When I use Optional, I get the correct printout of {test=MyTestPojo{value=Optional.empty}} . For some reason OptionalInt doesn't handle the empty case right here. I've tested without the yaml factory on a json file and it seems to work. I am using version 2.6.4 of Jackson.
The text was updated successfully, but these errors were encountered:
(moved from one reported at old
jackson-datatype-jdk8
, issue 32)When deserializing a yaml file if my pojo has OptionalInt rather than Optional, the empty case doesn't seem to be handled right.
Test file:
Test pojo class:
And the driving code:
When this file is deserialized with this code, I get a response of
{test=MyTestPojo{value=OptionalInt[0]}}
(as in, it's an optionalint that's present with a value of 0). When I use Optional, I get the correct printout of{test=MyTestPojo{value=Optional.empty}}
. For some reason OptionalInt doesn't handle the empty case right here. I've tested without the yaml factory on a json file and it seems to work. I am using version 2.6.4 of Jackson.The text was updated successfully, but these errors were encountered: