Package org.eclipse.persistence.jaxb
Class MarshallerProperties
java.lang.Object
org.eclipse.persistence.jaxb.MarshallerProperties
These are properties that may be set on an instance of Marshaller. Below is
an example of using the property mechanism to enable MOXy's JSON binding for
an instance of Marshaller.
Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Property for setting preferred or custom validator factory.static final String
Property for setting bean validation target groups.static final String
Property for setting bean validation mode.static final String
Property for disabling Bean Validation optimisations.static final String
The Constant CHARACTER_ESCAPE_HANDLER.static final String
The Constant INDENT_STRING.static final String
The name of the property used to specify a value that will be prepended to all keys that are mapped to an XML attribute.static final String
Disable generation of "item" name in nested arrays in JSON.static final String
The name of the property used to specify in the root node should be included in the message (default is true).static final String
The Constant JSON_MARSHAL_EMPTY_COLLECTIONS.static final String
The name of the property used to specify the character (default is '.') that separates the prefix from the key name.static final String
The Constant JSON_REDUCE_ANY_ARRAYS.static final String
Override default type property name for JSON as MOXy type discriminator.static final String
If we should treat unqualified type property in JSON as MOXy type discriminator.static final String
If there should be xsd prefix when using simple types, e.g.static final String
The name of the property used to specify the key that will correspond to the property mapped with @XmlValue.static final String
The Constant JSON_WRAPPER_AS_ARRAY_NAME.static final String
The name of the property used to specify the type of binding to be performed.static final String
Property for logging Entities content during marshalling/unmarshalling operation in MOXy.static final String
Property for MOXy logging level.static final String
The Constant NAMESPACE_PREFIX_MAPPER.static final String
-
Constructor Summary
-
Method Summary
-
Field Details
-
CHARACTER_ESCAPE_HANDLER
The Constant CHARACTER_ESCAPE_HANDLER. Allows for customization of character escaping when marshalling. Value should be an implementation of org.eclipse.persistence.oxm.CharacterEscapeHandler.- See Also:
-
INDENT_STRING
The Constant INDENT_STRING. Property used to set the string used when indenting formatted marshalled documents. The default for formatted documents is " " (three spaces).- See Also:
-
JSON_ATTRIBUTE_PREFIX
The name of the property used to specify a value that will be prepended to all keys that are mapped to an XML attribute. By default there is no attribute prefix. There is no effect when media type is "application/xml". When this property is specified at the JAXBContext level all instances of Marshaller and Unmarshaller will default to this attribute prefix. -
JSON_INCLUDE_ROOT
The name of the property used to specify in the root node should be included in the message (default is true). There is no effect when media type is "application/xml". When this property is specified at the JAXBContext level all instances of Marshaller and Unmarshaller will default to this setting. -
JSON_NAMESPACE_SEPARATOR
The name of the property used to specify the character (default is '.') that separates the prefix from the key name. It is only used if namespace qualification has been enabled be setting a namespace prefix mapper. When this property is specified at the JAXBContext level all instances of Marshaller and Unmarshaller will default to this setting. -
JSON_VALUE_WRAPPER
The name of the property used to specify the key that will correspond to the property mapped with @XmlValue. This key will only be used if there are other mapped properties. When this property is specified at the JAXBContext level all instances of Marshaller and Unmarshaller will default to this setting. -
MEDIA_TYPE
The name of the property used to specify the type of binding to be performed. When this property is specified at the JAXBContext level all instances of Marshaller and Unmarshaller will default to this media type. Supported values are:- MediaType.APPLICATION_XML (default)
- MediaType.APPLICATION_JSON
- "application/xml"
- "application/json"
-
NAMESPACE_PREFIX_MAPPER
The Constant NAMESPACE_PREFIX_MAPPER. Provides a means to customize the namespace prefixes used while marshalling to XML. Used for both marshal and unmarshal when mediaType is set to "application/json". Value is either a Map of URIs to prefixes, or an implementation of org.eclipse.persistence.oxm.NamespacePrefixMapper.- See Also:
-
JSON_MARSHAL_EMPTY_COLLECTIONS
The Constant JSON_MARSHAL_EMPTY_COLLECTIONS. If true an empty or null collection will be marshalled as null or empty array, if false both will be represented as an absent node.- See Also:
-
JSON_REDUCE_ANY_ARRAYS
The Constant JSON_REDUCE_ANY_ARRAYS. If true arrays that have just one item in them will be reduced and marshalled as a single item and not as a collection. ie: no [ ] in the marshalled JSON Default is false so all collections (even size 1) will have the [ ] around them.- See Also:
-
JSON_USE_XSD_TYPES_WITH_PREFIX
If there should be xsd prefix when using simple types, e.g. xsd.int. -
JSON_TYPE_COMPATIBILITY
If we should treat unqualified type property in JSON as MOXy type discriminator. -
JSON_TYPE_ATTRIBUTE_NAME
Override default type property name for JSON as MOXy type discriminator. Settings from binding file have higher priority.Example
Given the following property
marshaller.setProperty(MarshallerProperties.JSON_TYPE_ATTRIBUTE_NAME, "mytype");
If the property is set the JSON output will be:
... { "mytype": "phone", "contactId": 3, "number": "987654321" } ...
for following object model
@XmlSeeAlso({Address.class, Phone.class}) public class Contact { public int contactId; ...
public class Phone extends Contact{ public String number; ...
If the property is not set (default value) the JSON output will be:
... { "type": "phone", "contactId": 3, "number": "987654321" } ...
Unmarshaller will use it as type discriminator to select right child class. -
JSON_DISABLE_NESTED_ARRAY_NAME
Disable generation of "item" name in nested arrays in JSON. Settings from binding file have higher priority.Example
Given the following property
marshaller.setProperty(MarshallerProperties.JSON_DISABLE_NESTED_ARRAY_NAME, "false");
If the property value is set to false (default) the JSON output will be:
... "char2dArray":[ {"item":["a","b","c","d"]}, {"item":["e","f","g","h"]} ] ...
for following object model
... @XmlElement(name="char2dArray") private char[][] char2dArray; ...
If the property value is set to true (default) the JSON output will be:
... "char2dArray": [ ["a","b","c","d"], ["e","f","g","h"] ] ...
- See Also:
-
OBJECT_GRAPH
- See Also:
-
JSON_WRAPPER_AS_ARRAY_NAME
The Constant JSON_WRAPPER_AS_ARRAY_NAME. If true the grouping element will be used as the JSON key. There is no effect when media type is "application/xml". When this property is specified at the JAXBContext level all instances of Marshaller and Unmarshaller will default to this.Example
Given the following class:
@XmlAccessorType(XmlAccessType.FIELD) public class Customer { @XmlElementWrapper(name="phone-numbers") @XmlElement(name="phone-number") private List<PhoneNumber> phoneNumbers; }
If the property is set to false (the default) the JSON output will be:
{ "phone-numbers" : { "phone-number" : [ { ... }, { ... }] } }
And if the property is set to true, then the JSON output will be:
{ "phone-numbers" : [ { ... }, { ... }] }
-
BEAN_VALIDATION_MODE
Property for setting bean validation mode. Valid valuesBeanValidationMode.AUTO
(default),BeanValidationMode.CALLBACK
,BeanValidationMode.NONE
. -
BEAN_VALIDATION_FACTORY
Property for setting preferred or custom validator factory. Mapped value must be instance ofValidatorFactory
. -
BEAN_VALIDATION_GROUPS
Property for setting bean validation target groups. Mapped value must be of type Class[]. -
BEAN_VALIDATION_NO_OPTIMISATION
Property for disabling Bean Validation optimisations. Bean Validation in MOXy features optimisations, which are used to skip BV processes on non-constrained objects. This is to make maintenance easier and to allow for debugging in case that some object is not validated, but should be. Usage: set toBoolean.TRUE
to disable optimisations, set toBoolean.FALSE
to re-enable them again. -
MOXY_LOGGING_LEVEL
Property for MOXy logging level. This is to make maintenance easier and to allow MOXy generate more diagnostic log messages. Allowed values are specified inLogLevel
Default value isLogLevel.INFO
-
MOXY_LOG_PAYLOAD
Property for logging Entities content during marshalling/unmarshalling operation in MOXy. It calls toString() method from entity. This is to make maintenance easier and to allow for debugging to check marshalled/unmarshalled content. Use it carefully. It can produce high amount of data in the log files. Usage: set toBoolean.TRUE
to enable payload logging, set toBoolean.FALSE
to disable it. It can be set via system property with name "eclipselink.logging.payload.moxy" too. By default it is disabled.
-
-
Constructor Details
-
MarshallerProperties
public MarshallerProperties()
-