Skip to content

XML handling

Installation (Gradle)

compile group: "org.http4k", name: "http4k-format-xml", version: "3.174.0"

compile group: "org.http4k", name: "http4k-format-jackson-xml", version: "3.174.0"

About

These modules provide auto-marshalling functionality to convert XML into arbitrary data classes. The 2 differ slightly in their behaviour, due to the underlying libraries used for implementation. We recommend using http4k-format-jackson-xml as it has more predictable and consistent behaviour.

JacksonXml

  • Provides bi-directional conversion
  • Does NOT expose an XML DOM node model
  • Generally requires Jackson field annotations to manipulate output format
  • Provides extension point to map custom types using BiDiMapping registration (so supports all Java and Http4k primitives such as Uri)

JacksonXML Code

  • Provides extraction conversion only
  • Exposes an XML DOM node model as a first-class citizen - so can read directly from a string into a DOM model
  • Does not generate a wrapper element to represent the parent node
  • Has trouble with repeating child-elements, depending on zero, one or many elements in the XML. This is due to the underlying library implementation
  • Only handles objects with primitive JDK types

Xml

As above, we recommend using http4k-format-jackson-xml as it has more predictable and consistent behaviour.

XML Code