XML

XML (Extensible Markup Language) is a W3C standard format for structured information. It has a large eco-system of additional standards and tools.

In Java there are many different APIs and frameworks for accessing, producing and processing XML. For the devonfw we recommend to use JAXB for mapping Java objects to XML and vice-versa. Further there is the popular DOM API for reading and writing smaller XML documents directly. When processing large XML documents StAX is the right choice.

JAXB

We use JAXB to serialize Java objects to XML or vice-versa.

JAXB and Inheritance

Use @XmlSeeAlso annotation to provide sub-classes. See section "Collective Polymorphism" described here.

JAXB Custom Mapping

In order to map custom datatypes or other types that do not follow the Java bean conventions, you need to define a custom mapping. If you create dedicated objects for the XML mapping you can easily avoid such situations. When this is not suitable use @XmlJavaTypeAdapter and provide an XmlAdapter implementation that handles the mapping. For details see here.

Security

To prevent XML External Entity attacks, follow JAXP Security Guide and enable FSP.

Last updated 2023-11-20 10:37:01 UTC