Class MarshallerProperties


  • public class MarshallerProperties
    extends Object
    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 Detail

      • CHARACTER_ESCAPE_HANDLER

        public static final String 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.
        Since:
        2.3.3
        See Also:
        CharacterEscapeHandler, Constant Field Values
      • INDENT_STRING

        public static final String 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).
        Since:
        2.3.3
        See Also:
        Constant Field Values
      • MEDIA_TYPE

        public static final String 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"
        Since:
        2.4
        See Also:
        JAXBContextProperties.MEDIA_TYPE, UnmarshallerProperties.MEDIA_TYPE, MediaType, Constant Field Values
      • NAMESPACE_PREFIX_MAPPER

        public static final String 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.
        Since:
        2.3.3
        See Also:
        NamespacePrefixMapper, Constant Field Values
      • JSON_MARSHAL_EMPTY_COLLECTIONS

        public static final String 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.
        Since:
        2.4
        See Also:
        Constant Field Values
      • JSON_REDUCE_ANY_ARRAYS

        public static final String 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.
        Since:
        2.4.2
        See Also:
        Constant Field Values
      • JSON_TYPE_ATTRIBUTE_NAME

        public static final String 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.
        Since:
        2.7.4
        See Also:
        JAXBContextProperties.JSON_TYPE_ATTRIBUTE_NAME, UnmarshallerProperties.JSON_TYPE_ATTRIBUTE_NAME, Constant Field Values
      • JSON_DISABLE_NESTED_ARRAY_NAME

        public static final String 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"]
         ]
         ...
         
        Since:
        2.7.5
        See Also:
        Constant Field Values
      • JSON_WRAPPER_AS_ARRAY_NAME

        public static final String 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" : [ {
                 ...
             }, {
                 ...
             }]
         }
         
        Since:
        2.4.2
        See Also:
        JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME, UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, Constant Field Values
      • MOXY_LOG_PAYLOAD

        public static final String 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 to Boolean.TRUE to enable payload logging, set to Boolean.FALSE to disable it. It can be set via system property with name "eclipselink.logging.payload.moxy" too. By default it is disabled.
        Since:
        3.0
        See Also:
        JAXBContextProperties.MOXY_LOG_PAYLOAD, UnmarshallerProperties.MOXY_LOG_PAYLOAD, Constant Field Values
    • Constructor Detail

      • MarshallerProperties

        public MarshallerProperties()