Skip to main content
Jump to: navigation, search


Design Documentation: IndentString

ER 370574

In the current JAXB RI, developed by Sun, there are a series of "proprietary" JAXB extensions that are available to provide advanced JAXB functionality outside of the JAXB spec.

The Marshaller property com.sun.xml.bind.indentString provided in the Sun JAXB implementation allows users to override the indent string that is used when marshalling objects.

This document will outline the design for an EclipseLink equivalent to this extension.


  • Provide support in EclipseLink's JAXBMarshaller to customize the indent string used.
  • Allow the usage of Sun JAXB property names to set this feature, so that no code changes are required for users migrating from Sun to EclipseLink JAXB.


If a custom indent string has been set on the Marshaller, then an element of depth k will be indented by printing this string k times. Custom indenting is only applicable if the Marshaller property Marshaller.JAXB_FORMATTED_OUTPUT / "jaxb.formatted.output" is enabled.

EclipseLink's default indent string is "   " (three spaces).


A custom indent string can be specified on a Marshaller using the addProperty() method:

JAXBContext ctx = ...
Marshaller m = ctx.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.setProperty(org.eclipse.persistence.jaxb.JAXBMarshaller.INDENT_STRING, " "); // one space

Note: EclipseLink also supports Sun's indentString property names:

m.setProperty("com.sun.xml.bind.indentString", " ");
m.setProperty("com.sun.xml.internal.bind.indentString", " ");

Document History

Date Author Version Description & Notes
120207 Rick Barkhouse 1.00 : First draft
120222 Rick Barkhouse 1.10 : Updated property name

Back to the top