Parsing of `null` Integer fields changed behavior between version 2.11.4 and 2.12.X
See original GitHub issueRunning version 2.11.4
using the following configuration:
// Create new mapper
final JacksonXmlModule module = new JacksonXmlModule();
module.setDefaultUseWrapper(false);
final XmlMapper mapper = new XmlMapper(module);
// Configure it
mapper
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
.registerModule(new JodaModule())
.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
Parsing the following xml:
<campaign>
<id>123</id>
<name>Website Tracking</name>
<cost/>
</campaign>
into the following bean:
public class Campaign {
private Long id;
private String name;
private Integer cost;
public Long getId() {
return id;
}
public String getName() {
return name;
}
public Integer getCost() {
return cost;
}
public void setId(final Long id) {
this.id = id;
}
public void setName(final String name) {
this.name = name;
}
public void setCost(final Integer cost) {
this.cost = cost;
}
}
usage:
// mapper instance as defined above, campaignXmlStr as defined above.
mapper.readValue(campaignXmlStr, Campaign.class);
The above JSON gets deserialized into the bean with the cost
property being set to null
.
With version 2.12.x
the cost
property becomes integer 0
I reviewed the release notes and didn’t notice any breaking change listed in behavior. Is this change expected?
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Index (jackson-databind 2.11.4 API) - javadoc.io
Defines interface for resolvers that can resolve abstract types into concrete ones; either by using static mappings, or possibly by materializing ...
Read more >R2022-10v2 (monthly release cumulative patch) - 8.0
Download the patch from the Settings->Software Update page into the nexus repository. Log in to Talend Studio in the remote mode. If your...
Read more >15.1.2. Eve JSON Format - Suricata Docs
Event type: SSH¶. 15.1.2.12.1. Fields¶. “proto_version”: The protocol version transported with the ssh protocol (1.x ...
Read more >BigQuery Could not parse 'null' as int for field - Stack Overflow
You'll need to transform the data in order to end up with the expected schema and data. Instead of INTEGER, specify the column...
Read more >µPickle 2.0.0
Scala Versions. uPickle does not support Scala 2.10; only 2.11/2.12/2.13/3.x are ... own JSON parser, which provides the best performance in Scala.js
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll have to think about this for a bit – change itself would not have been planned, but handling of “empty” values with XML is rather tricky as conceptually
is identical to
and in both cases logical textual content to process is empty String (“”). Handling of that did change internally to allow dealing with this case for POJOs (to end up with “empty” Objects).
But I can see how such values should ideally become either
null
forNumber
wrappers or, in case of primitives likeint
, probably result in exception.So I think that this change is a side effect of legitimate fixes for non-scalar types.
thanks!