FasterXML / jackson-module-jaxb-annotations

(DEPRECATED!!!) Moved to: https://github.com/FasterXML/jackson-modules-base/
https://github.com/FasterXML/jackson-modules-base
44 stars 20 forks source link

Jackson does not ignore whitespace in XML element #67

Open shevek opened 7 years ago

shevek commented 7 years ago

To reproduce: git clone git@github.com:shevek/bugs-tests-and-examples.git git checkout jackson-xml-whitespace ./gradlew installDist && ./build/install/bugs-tests-and-examples/bin/bugs-tests-and-examples

Actual behaviour:

Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "" (class org.anarres.tests.Datasource$Column), not marked as ignorable (2 known properties: "members", "role"])
 at [Source: java.io.BufferedInputStream@2c039ac6; line: 6, column: 40] (through reference chain: org.anarres.tests.Workbook["datasources"]->java.util.ArrayList[0]->org.anarres.tests.Datasource["column"]->java.util.ArrayList[0]->org.anarres.tests.Datasource$Column[""])

Variants of expected behaviour: When tweaking the XML file a bit:

Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token

Expected behaviour: Ignores whitespace in empty list element and does not attempt to synthesize a value out of it.

Related issues:

Thank you.

cowtowncoder commented 7 years ago

Do you mean empty value for list itself, or for element within list? Former would perhaps make sense; latter less so. I assume it is former.

shevek commented 7 years ago

I'm not entirely out of my depth here, but I'm heading that way, hence the very concrete example. My objective is just to deserialize that file, so any workaround which does so will be gratefully received. Fundamentally:

<outer>
</outer>

annotated as

@XmlElementWrapper("outer")
@XmlElement("inner")
List<Inner> inner;

doesn't deserialize, and I want it to. I had a bunch of related issues when I did have inner elements, like Jackson reporting an error message for an Inner field as missing on the element enclosing Outer, and so forth - if we get past this stage and I re-hit that, I'll put up another test case.

cowtowncoder commented 7 years ago

Ok, yes, that makes sense. I was referring to potential alternate case of

<outer>
  <inner>
  </inner>
</outer>

which would not be similarly possible to handle by ignoring it (although there's separate question of what should become of it -- just can not ignore such element of collection). Thank you for clarifying the case.

shevek commented 7 years ago

The larger case was:

<root>
<outer>
<inner name="value">
</outer>
</root>

And Jackson was reporting 'name' as a missing property on outer, rather than instantiating it on 'inner'. Cutting that example down got me here, and if we get past this, I will reinstate that larger example, and submit it to you.

shevek commented 7 years ago

If it were possible to override XmlFactory._initializeXmlReader then I could:

return _xmlInputFactory.createFilteredReader(r,
                        new StreamFilter() {
                            @Override
                            public boolean accept(XMLStreamReader r) {
                                return !r.isWhiteSpace();
                            }
                        });

but I can't because it's final. But if there were some way to inject this wrapper, then it would make the test pass.

shevek commented 7 years ago

Actually, that workaround only makes the smaller test pass. Now I'm back to the bug where it's mis-reporting and mis-applying the location of a field. I'll make up another example.

shevek commented 7 years ago

I've updated the github repository; if you pull, you will now find one instance of each failure. Really, it's the second that's killing me. Thank you!

shevek commented 7 years ago

In my production code, I added SimpleXML ( http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php ) annotations to all the beans, and it loads fine, so I'm a bit less stressed than I was earlier, and I've proved that my model is good for the XML. So now it's just a question of whether we can make Jackson do it.

cowtowncoder commented 6 years ago

Project moved, need to re-file at:

https://github.com/FasterXML/jackson-modules-base/issues

@shevek Do you think you could re-create with up-to-date description, based on your understanding of the state? Can add link back to this issue (for additional discussion).

darioseidl commented 5 years ago

I'm having exactly the same problem. I'm not using any JAXB annotations (neither did @shevek afaict), only jackson-module-xml, so this should probably be reported there?

Btw. the workaround in the StackOverflow post worked for me.