Open
Description
Please consider the following scenario:
public record Bar(ArrayList<String> bar) {}
void main() throws JsonProcessingException {
var bar = new XmlMapper().readValue("<Bar></Bar>", Bar.class);
System.out.println(bar); // Desired output: Bar[bar=[]]
}
As stated in the comment in above code, I'd like missing values to be deserialized into an empty list. So far I managed to make this possible with these two approaches:
- Add a custom constructor to the
Bar
record which takes care ofnull
and returns an empy list. - Write a custom
StdDeserializer
forBar
.
I'd like to avoid approach 1) because I'd like to keep the parsing related functionality to annotations and not have it inside the record class. On the other hand, approach 2) requires a bigger setup. I was therefore wondering, is it possible to deserialize missing values into an empty list in an easier way - for example, like deserializing a missing value into an empty Optional
is supported by registering the Jdk8Module
- and if not, could this maybe be a feature in the future?
Metadata
Metadata
Assignees
Labels
No labels