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

Similar "JsonFormat.Feature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT" but for composite types #283

Closed
paroxysm opened this issue Apr 18, 2018 · 1 comment

Comments

@paroxysm
Copy link

paroxysm commented Apr 18, 2018

Hey guys,
So awhile ago an issue was fixed with the mapper de-serializing empty string types such as <first/> into a null, as opposed to a "".

There's also a similar issue affecting composite types as well.
Consider pseudo-xsd:

<complexType name="Parent">
  <element name="child" type="Child" maxOccurs="0"/>
</complexType>

<complexType name="Child">
 <element name="member1"/>
 <element name="member2"/>
 <element name="member3"/>
...
</complexType>

If maven-jaxb-plugin generate POJOs for this, I get pseudo-java:

@XmlType( name="Parent") class Parent {  @XmlElement(name - "child") List<Child> child }
@XmlType(name="Child") class Child { ... }

Given an XmlMapper initialized as so:

XmlMapper mapper = new XmlMapper();
AnnotationIntrospector introspector= new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
mapper.setAnnotationIntrospectors(introspector, introspector);

If I try to deserialize:
<Parent/>

I'll end up with a null object.
However, one would expect to end up with a non-null instance of "Parent", that has an empty or null list of "Child"

EDIT: Just realized I created a duplicate of #209

@paroxysm paroxysm changed the title JsonFormat.Feature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT but for composite types Similar "JsonFormat.Feature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT" but for composite types Apr 18, 2018
@cowtowncoder
Copy link
Member

In theory, this is what 2.9 feature for configurable nulls:

FasterXML/jackson-databind#1402

should allow. Unfortunately there seems to be something preventing it with XML; I will be filing a new issue for that.
And yes, this is same as #209, so closing.

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

No branches or pull requests

2 participants