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.

null-handling ignored

See original GitHub issue

With 2.12.1-SNAPSHOT the following code:

        XML_MAPPER = new XmlMapper();
        XML_MAPPER.configOverride(List.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
        XML_MAPPER.configOverride(Set.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
        XML_MAPPER.configOverride(Map.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
        XML_MAPPER.enable(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL);

        List<LoggerTO> original = new ArrayList<>();

        StringWriter writer = new StringWriter();
        XML_MAPPER.writeValue(writer, original);

        List<LoggerTO> actual = XML_MAPPER.readValue(writer.toString(), new TypeReference<List<LoggerTO>>() {
        });
        assertEquals(original, actual);

fails with message

org.opentest4j.AssertionFailedError: expected: <[]> but was: <null>

I have verified that serialization produces

<ArrayList/>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:22 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Jan 1, 2021

For what it is worth, empty element like <ArrayList></ArrayList> (or <ArrayList />) should be deserialized as empty List with 2.12, as long as you do NOT enable FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL. This was not the case with 2.11, regardless of setting as handling of empty elements had problems – mostly because at low level such elements would be equivalent to JSON empty String value. Support for this case was improved in jackson-databind 2.12, to let XML module work better for this relatively common case.

I hope it is now possible to get things to work in a usable way: unfortunately the full combination of various aspects is not easy to reason about and it can be frustrating to find a good combination. Especially when attempting to make things work the same way against different versions.

I am planning to release 2.12.1 very soon now, for what that is worth; there are a few important fixes.

0reactions
ilgrossocommented, Dec 31, 2020

FYI with these settings all is passing now, both with 2.11 and 2.12.1-SNAPSHOT: https://github.com/ilgrosso/jackson-dataformat-xml-437/blob/main/src/test/java/net/tirasa/test/XMLTest.java#L23-L39

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullValueHandling setting - Json.NET
This sample serializes an object to JSON with NullValueHandling set to Ignore so that properties with a default value aren't included in the...
Read more >
How to ignore a property in class if null, using json.net
Include to :=NullValueHandling.Ignore. By the way - I've found that you can decorate a property for both XML and JSON serialization just fine...
Read more >
ExampleMatcher.NullHandler (Spring Data Core 3.0.0 API)
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum...
Read more >
JSON serialization: Ignore selective properties or null properties
This article is to explain how to ignore null values or some properties from being ... NullValueHandling = NullValueHandling.Ignore
Read more >
NULL Semantics - Spark 3.0.0-preview Documentation
Null handling in null-in-tolerant expressions; Null handling Expressions that ... NULL values are ignored from processing by all the aggregate functions.
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