Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of null values in string Arrays and Collections #585

Merged
merged 1 commit into from
Mar 18, 2023

Conversation

mbladel
Copy link
Contributor

@mbladel mbladel commented Mar 17, 2023

Possible fix for #584.

As a note, empty and null string values in Maps were correctly handled even before the change (although requiring the map itself to be wrapped in a POJO). I included a test anyways.

import static org.junit.Assert.assertNull;

// [dataformat-xml#584]
public class StringListRoundtripTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but one big(ger) ask: in addition to root values (which are actually harder to support, bit less common to use), would it be possible to also add "as-property" cases where String arrays, Collections, Maps are properties of POJOs? That would we can double-check that empty Strings do not accidentally become nulls, which is my main concern.

@@ -932,12 +932,11 @@ public String nextTextValue() throws IOException
switch (token) {
case XmlTokenStream.XML_END_ELEMENT:
if (_mayBeLeaf) {
// NOTE: this is different from nextToken() -- produce "", NOT null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this explicit comment makes me nervous: it specifically spells out that when asking from nextTextValue(), empty element should not be coerced into null.

But since all existing unit tests, and new ones too, pass, this may make sense.

One related note: the reason Maps work ok is that there is no specialized access to "String-valued maps" (but there is for String[] and Collection<String>!) to use JsonParser.nextTextValue().

One way to alleviate my concerns is to make sure tests are improved -- I noticed additions which are great.
The main addition I'd like to see is addition of checking of String[] / List<String> valued POJO properties, with null, "". If those retain values as expected I am comfortable with this change.

_mayBeLeaf = false;
_currToken = JsonToken.VALUE_STRING;
_currToken = JsonToken.VALUE_NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add one-line comment referencing

/ / [dataformat-xml#584]: retain null values

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I can do that.

@cowtowncoder
Copy link
Member

Since I am pushing 2.15.0-rc1 soon, I will actually merge this & add comment. We shoyld be able to get some validation on safety with rc1, more so than waiting until rc2 or 2.15.0 final.

Additional tests would be great but can be another PR.

@cowtowncoder cowtowncoder merged commit 0c6a4fb into FasterXML:2.15 Mar 18, 2023
@cowtowncoder cowtowncoder added this to the 2.15.0-rc1 milestone Mar 18, 2023
@mbladel mbladel deleted the string_collections branch March 19, 2023 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants