question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parsing of `null` Integer fields changed behavior between version 2.11.4 and 2.12.X

See original GitHub issue

Running 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:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, May 2, 2021

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

<element />

is identical to

<element></element>

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 for Number wrappers or, in case of primitives like int, probably result in exception.

So I think that this change is a side effect of legitimate fixes for non-scalar types.

0reactions
Crimcommented, May 4, 2021

thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found