com.sun.jersey.api.json
Class JSONConfiguration

java.lang.Object
  extended by com.sun.jersey.api.json.JSONConfiguration

public class JSONConfiguration
extends java.lang.Object

An immutable configuration of JSON notation and options. JSONConfiguration could be used for configuring the JSON notation on JSONJAXBContext

Author:
[email protected]

Nested Class Summary
static class JSONConfiguration.Builder
          Builder class for constructing JSONConfiguration options
static class JSONConfiguration.MappedBuilder
          Builder class for constructing JSONConfiguration options for the JSONConfiguration.Notation.MAPPED convention.
static class JSONConfiguration.MappedJettisonBuilder
          Builder class for constructing JSONConfiguration options for the JSONConfiguration.Notation.MAPPED_JETTISON convention.
static class JSONConfiguration.NaturalBuilder
          Builder class for constructing JSONConfiguration options for the JSONConfiguration.Notation.NATURAL convention.
static class JSONConfiguration.Notation
          Enumeration of supported JSON notations.
 
Field Summary
static JSONConfiguration DEFAULT
          The default JSONConfiguration uses JSONConfiguration.Notation.MAPPED notation with root unwrapping option set to true.
static java.lang.String FEATURE_POJO_MAPPING
          A ResourceConfig feature, which allows you to enable JSON/POJO mapping functionality in Jersey.
 
Method Summary
static JSONConfiguration.Builder badgerFish()
          A static method for obtaining a builder of JSONConfiguration instance, which will use JSONConfiguration.Notation.BADGERFISH JSON notation.
static JSONConfiguration.Builder copyBuilder(JSONConfiguration jc)
           
static JSONConfiguration createJSONConfigurationWithFormatted(JSONConfiguration c, boolean formatted)
          A static method for obtaining JSONConfiguration instance with humanReadableFormatting set according to formatted parameter.
static JSONConfiguration createJSONConfigurationWithRootUnwrapping(JSONConfiguration c, boolean rootUnwrapping)
          A static method for obtaining JSONConfiguration instance with rootUnwrapping set according to formatted parameter.
 java.util.Collection<java.lang.String> getArrays()
          Returns JSON array names property This property is valid for the JSONConfiguration.Notation.MAPPED notation only.
 java.util.Collection<java.lang.String> getAttributeAsElements()
          Returns names of attributes, which will be handled as elements This property is valid for the JSONConfiguration.Notation.MAPPED notation only.
 java.util.Collection<java.lang.String> getNonStrings()
          Returns names of JSON objects, which will be serialized out as non-strings, i.e.
 JSONConfiguration.Notation getNotation()
          Returns JSON notation selected for this configuration
 java.lang.Character getNsSeparator()
          Returns XML namespace separator, which is used when constructing JSON identifiers for XML elements/attributes in other than default namespace This property is valid for the JSONConfiguration.Notation.MAPPED notation only.
 java.util.Map<java.lang.String,java.lang.String> getXml2JsonNs()
          Returns a map for XML to JSON namespace mapping This property is valid for the JSONConfiguration.Notation.MAPPED notation only.
 boolean isHumanReadableFormatting()
          Says if the output JSON will be formatted with new-line characters and indentation so that it is easy to read for people.
 boolean isRootUnwrapping()
          Says if the root element will be stripped off This property is valid for the JSONConfiguration.Notation.MAPPED and JSONConfiguration.Notation.NATURAL notations.
 boolean isUsingPrefixesAtNaturalAttributes()
          Says if the JSON names corresponding to XML attributes should use a '@' prefix.
static JSONConfiguration.MappedBuilder mapped()
          A static method for obtaining a builder of JSONConfiguration instance, which will use JSONConfiguration.Notation.MAPPED JSON notation.
static JSONConfiguration.MappedJettisonBuilder mappedJettison()
          A static method for obtaining a builder of JSONConfiguration instance, which will use JSONConfiguration.Notation.MAPPED_JETTISON JSON notation.
static JSONConfiguration.NaturalBuilder natural()
          A static method for obtaining a builder of JSONConfiguration instance, which will use JSONConfiguration.Notation.NATURAL JSON notation.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FEATURE_POJO_MAPPING

public static final java.lang.String FEATURE_POJO_MAPPING
A ResourceConfig feature, which allows you to enable JSON/POJO mapping functionality in Jersey. If set to true, your application will be capable of transforming JSON data to and out of POJOs. This also includes any JAXB beans existing in your application. I.e. all those beans would not be processed via XML, but rather directly marshaled and un-marshaled to and from JSON using the POJO mapping functionality.

See Also:
Constant Field Values

DEFAULT

public static final JSONConfiguration DEFAULT
The default JSONConfiguration uses JSONConfiguration.Notation.MAPPED notation with root unwrapping option set to true.

Method Detail

createJSONConfigurationWithFormatted

public static JSONConfiguration createJSONConfigurationWithFormatted(JSONConfiguration c,
                                                                     boolean formatted)
                                                              throws java.lang.IllegalArgumentException
A static method for obtaining JSONConfiguration instance with humanReadableFormatting set according to formatted parameter.

Parameters:
c - original instance of JSONConfiguration, can't be null
formatted -
Returns:
copy of provided JSONConfiguration with humanReadableFormatting set to formatted.
Throws:
java.lang.IllegalArgumentException - when provided JSONConfiguration is null.

createJSONConfigurationWithRootUnwrapping

public static JSONConfiguration createJSONConfigurationWithRootUnwrapping(JSONConfiguration c,
                                                                          boolean rootUnwrapping)
                                                                   throws java.lang.IllegalArgumentException
A static method for obtaining JSONConfiguration instance with rootUnwrapping set according to formatted parameter.

Parameters:
c - original instance of JSONConfiguration, can't be null
rootUnwrapping -
Returns:
copy of provided JSONConfiguration with humanReadableFormatting set to formatted.
Throws:
java.lang.IllegalArgumentException - when provided JSONConfiguration is null.

natural

public static JSONConfiguration.NaturalBuilder natural()
A static method for obtaining a builder of JSONConfiguration instance, which will use JSONConfiguration.Notation.NATURAL JSON notation. After getting the builder, you can set configuration options on it, and finally get an immutable JSONConfiguration instance using the JSONConfiguration.Builder.build() method.

Returns:
a builder for JSONConfiguration instance

mapped

public static JSONConfiguration.MappedBuilder mapped()
A static method for obtaining a builder of JSONConfiguration instance, which will use JSONConfiguration.Notation.MAPPED JSON notation. After getting the builder, you can set configuration options on it and finally get an immutable JSONConfiguration instance the using JSONConfiguration.Builder.build() method.

Returns:
a builder for JSONConfiguration instance

mappedJettison

public static JSONConfiguration.MappedJettisonBuilder mappedJettison()
A static method for obtaining a builder of JSONConfiguration instance, which will use JSONConfiguration.Notation.MAPPED_JETTISON JSON notation. After getting the builder, you can set configuration options on it and finally get an immutable JSONConfiguration instance using the JSONConfiguration.Builder.build() method.

Returns:
a builder for JSONConfiguration instance

badgerFish

public static JSONConfiguration.Builder badgerFish()
A static method for obtaining a builder of JSONConfiguration instance, which will use JSONConfiguration.Notation.BADGERFISH JSON notation. After getting the builder, you can set configuration options on it and finally get an immutable JSONConfiguration instance using the JSONConfiguration.Builder.build() method.

Returns:
a builder for JSONConfiguration instance

copyBuilder

public static JSONConfiguration.Builder copyBuilder(JSONConfiguration jc)

getNotation

public JSONConfiguration.Notation getNotation()
Returns JSON notation selected for this configuration

Returns:
JSON notation

getArrays

public java.util.Collection<java.lang.String> getArrays()
Returns JSON array names property This property is valid for the JSONConfiguration.Notation.MAPPED notation only.

Returns:
collection of array names
See Also:
JSONConfiguration.MappedBuilder.arrays(java.lang.String...)

getAttributeAsElements

public java.util.Collection<java.lang.String> getAttributeAsElements()
Returns names of attributes, which will be handled as elements This property is valid for the JSONConfiguration.Notation.MAPPED notation only.

Returns:
attribute as element names collection
See Also:
JSONConfiguration.MappedBuilder.attributeAsElement(java.lang.String...)

getXml2JsonNs

public java.util.Map<java.lang.String,java.lang.String> getXml2JsonNs()
Returns a map for XML to JSON namespace mapping This property is valid for the JSONConfiguration.Notation.MAPPED notation only.

Returns:
a map for XML to JSON namespace mapping
See Also:
JSONConfiguration.MappedBuilder.xml2JsonNs(java.util.Map)

getNsSeparator

public java.lang.Character getNsSeparator()
Returns XML namespace separator, which is used when constructing JSON identifiers for XML elements/attributes in other than default namespace This property is valid for the JSONConfiguration.Notation.MAPPED notation only.

Returns:
XML namespace separator character
See Also:
JSONConfiguration.MappedBuilder.nsSeparator(java.lang.Character)

getNonStrings

public java.util.Collection<java.lang.String> getNonStrings()
Returns names of JSON objects, which will be serialized out as non-strings, i.e. without delimiting their values with double quotes This property is valid for the JSONConfiguration.Notation.MAPPED notation only.

Returns:
name of non-string JSON objects
See Also:
JSONConfiguration.MappedBuilder.nonStrings(java.lang.String...)

isRootUnwrapping

public boolean isRootUnwrapping()
Says if the root element will be stripped off This property is valid for the JSONConfiguration.Notation.MAPPED and JSONConfiguration.Notation.NATURAL notations.

Returns:
true, if root element has to be stripped off
See Also:
JSONConfiguration.MappedBuilder.rootUnwrapping(boolean)

isUsingPrefixesAtNaturalAttributes

public boolean isUsingPrefixesAtNaturalAttributes()
Says if the JSON names corresponding to XML attributes should use a '@' prefix. This property is valid for the JSONConfiguration.Notation.NATURAL notation only.

Returns:
true, if prefixes are added
See Also:
JSONConfiguration.NaturalBuilder.usePrefixesAtNaturalAttributes()

isHumanReadableFormatting

public boolean isHumanReadableFormatting()
Says if the output JSON will be formatted with new-line characters and indentation so that it is easy to read for people. This property is valid for the JSONConfiguration.Notation.NATURAL notation only.

Returns:
true, if formatting is applied on the output JSON
See Also:
JSONConfiguration.NaturalBuilder.humanReadableFormatting(boolean)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2011 Oracle Corporation. All Rights Reserved.