0

According to this it is ok to have XML like

<root>
  asdasda
  <sub>qwertyuiop</sub>
</root>

However using Jackson XmlMapper (by default) to this kind of class:

@XmlRootElement
@Getter @Setter
public class Root {
    private String sub;
}

gives an error:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "" (class org.example.jackson.unwrap.TestIt1$Root), not marked as ignorable (one known property: "sub"]) ...

Ok, I can add

xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

and I will get everything else but root text 'asdasda'.

What should I add to have 'asdasda' also in some field of class Root instead of just ignoring it?

pirho
  • 11,565
  • 12
  • 43
  • 70

1 Answers1

1

It seems that it is not supported at all. From Jackson docs Known Limitations

Tree Model (JsonNode, ObjectMapper.readTree()) is based on JSON content model and it does not match exactly with XML infoset
Mixed content (both textual content and elements as children of an element) not supported: text, if any, will be lost

pirho
  • 11,565
  • 12
  • 43
  • 70