Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Development/370574"

 
(3 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
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.
 
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.  EclipseLink's default indent string is "   " (three spaces).
+
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.
 
This document will outline the design for an EclipseLink equivalent to this extension.
Line 14: Line 14:
 
= Requirements =
 
= Requirements =
  
* Provide support in EclipseLink's JAXBMarshaller to customize the indent string used.
+
* 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.
 
* 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.
  
Line 21: Line 21:
  
 
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.
 
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).
  
  
Line 33: Line 35:
 
Marshaller m = ctx.createMarshaller();
 
Marshaller m = ctx.createMarshaller();
 
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
 
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.setProperty(org.eclipse.persistence.jaxb.JAXBMarshaller.ECLIPSELINK_INDENT_STRING, " "); // one space
+
m.setProperty(org.eclipse.persistence.jaxb.JAXBMarshaller.INDENT_STRING, " "); // one space
 
...
 
...
 
</source>
 
</source>
Line 59: Line 61:
 
| Rick Barkhouse
 
| Rick Barkhouse
 
| 1.00 : First draft
 
| 1.00 : First draft
 +
|-
 +
| 120222
 +
| Rick Barkhouse
 +
| 1.10 : Updated property name
 
|}<br>
 
|}<br>

Latest revision as of 12:20, 22 February 2012

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.


Requirements

  • 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.


Behaviour

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).


Configuration

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