com.sun.jersey.api.json
Class JSONJAXBContext

java.lang.Object
  extended by javax.xml.bind.JAXBContext
      extended by com.sun.jersey.api.json.JSONJAXBContext
All Implemented Interfaces:
JSONConfigurated

public final class JSONJAXBContext
extends javax.xml.bind.JAXBContext
implements JSONConfigurated

An adaption of JAXBContext that supports marshalling and unmarshalling of JAXB beans using the JSON format.

The JSON format may be configured by using a JSONConfiguration object as a constructor parameter of this class.


Nested Class Summary
static class JSONJAXBContext.JSONNotation
          Deprecated. 
 
Field Summary
static java.lang.String JSON_ARRAYS
          Deprecated. 
static java.lang.String JSON_ATTRS_AS_ELEMS
          Deprecated. 
static java.lang.String JSON_ENABLED
          Deprecated. 
static java.lang.String JSON_NON_STRINGS
          Deprecated. 
static java.lang.String JSON_NOTATION
          Deprecated. 
static java.lang.String JSON_ROOT_UNWRAPPING
          Deprecated. 
static java.lang.String JSON_XML2JSON_NS
          Deprecated. 
static java.lang.String NAMESPACE
          Deprecated. 
 
Fields inherited from class javax.xml.bind.JAXBContext
JAXB_CONTEXT_FACTORY
 
Constructor Summary
JSONJAXBContext(java.lang.Class... classesToBeBound)
          Constructs a new instance with default JSONConfiguration.
JSONJAXBContext(java.lang.Class[] classesToBeBound, java.util.Map<java.lang.String,java.lang.Object> properties)
          Constructs a new instance with a custom set of properties.
JSONJAXBContext(JSONConfiguration config, java.lang.Class... classesToBeBound)
          Constructs a new instance with given JSONConfiguration.
JSONJAXBContext(JSONConfiguration config, java.lang.Class[] classesToBeBound, java.util.Map<java.lang.String,java.lang.Object> properties)
          Constructs a new instance with a custom set of properties.
JSONJAXBContext(JSONConfiguration config, java.lang.String contextPath)
          Construct a new instance of using context class loader of the thread with given JSONConfiguration.
JSONJAXBContext(JSONConfiguration config, java.lang.String contextPath, java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,java.lang.Object> properties)
          Construct a new instance using a specified class loader, set of properties and JSONConfiguration .
JSONJAXBContext(java.lang.String contextPath)
          Construct a new instance of using context class loader of the thread with default JSONConfiguration.
JSONJAXBContext(java.lang.String contextPath, java.lang.ClassLoader classLoader)
          Construct a new instance using a specified class loader with default JSONConfiguration.
JSONJAXBContext(java.lang.String contextPath, java.lang.ClassLoader classLoader, java.util.Map<java.lang.String,java.lang.Object> properties)
          Construct a new instance using a specified class loader and a custom set of properties.
 
Method Summary
 JSONMarshaller createJSONMarshaller()
          Create a JSON marshaller.
 JSONUnmarshaller createJSONUnmarshaller()
          Create a JSON unmarshaller.
 javax.xml.bind.Marshaller createMarshaller()
          Overrides underlaying createMarshaller method and returns a marshaller which is capable of JSON serialization.
 javax.xml.bind.Unmarshaller createUnmarshaller()
          Overrides underlaying createUnmarshaller method and returns an unmarshaller which is capable of JSON deserialization.
 javax.xml.bind.Validator createValidator()
          Simply delegates to underlying JAXBContext implementation.
 JSONConfiguration getJSONConfiguration()
          Get the JSON configuration.
static JSONMarshaller getJSONMarshaller(javax.xml.bind.Marshaller marshaller)
          Get a JSONMarshaller from a Marshaller.
static JSONUnmarshaller getJSONUnmarshaller(javax.xml.bind.Unmarshaller unmarshaller)
          Get a JSONUnmarshaller from a Unmarshaller.
 
Methods inherited from class javax.xml.bind.JAXBContext
createBinder, createBinder, createJAXBIntrospector, generateSchema, newInstance, newInstance, newInstance, newInstance, newInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMESPACE

@Deprecated
public static final java.lang.String NAMESPACE
Deprecated. 
A namespace for JSONJAXBContext related properties names.

See Also:
Constant Field Values

JSON_NOTATION

@Deprecated
public static final java.lang.String JSON_NOTATION
Deprecated. 
JSON notation property is now deprecated. See JSONConfiguration.

The type of this property is enum type JSONJAXBContext.JSONNotation.

The value may be one of the following that are the currently supported JSON notations: JSONNotation.MAPPED, JSONNotation.MAPPED_JETTISON and JSONNotation.BADGERFISH

The default value is JSONNotation.MAPPED.

See Also:
Constant Field Values

JSON_ENABLED

@Deprecated
public static final java.lang.String JSON_ENABLED
Deprecated. 
JSON enabled property is now deprecated. See JSONConfiguration.

The type of this property is Boolean

If set to true, JSON will be serialized/deserialized instead of XML

The default value is false.

See Also:
Constant Field Values

JSON_ROOT_UNWRAPPING

@Deprecated
public static final java.lang.String JSON_ROOT_UNWRAPPING
Deprecated. 
XML root element unwrapping property is now deprecated. See JSONConfiguration.

The type of this property is Boolean

If set to true, JSON code corresponding to the XML root element will be stripped out for JSONNotation.MAPPED (default) notation.

The default value is false.

See Also:
Constant Field Values

JSON_ARRAYS

@Deprecated
public static final java.lang.String JSON_ARRAYS
Deprecated. 
JSON arrays property is now deprecated. See JSONConfiguration. This property is valid for the JSONNotation.MAPPED notation only.

The type of this property is java.util.Collection<String>.

The value is a collection of string values that are object names. The value of an object name in the JSON document that exists in the collection of object names will be declared as an array, even if only one element is present.

For example, consider that the property value is not set and the JSON document is { ..., "arr1":"single element", ... }. If the property value is set to contain "arr1" then the JSON document would be { ..., "arr1":["single element"], ... }.

The default value is an empty collection.

See Also:
Constant Field Values

JSON_NON_STRINGS

@Deprecated
public static final java.lang.String JSON_NON_STRINGS
Deprecated. 
JSON non-string values property is now deprecated. See JSONConfiguration. This property is valid for the JSONNotation.MAPPED notation only.

The type of this property is Collection<String>.

The value is collection of string values that are object names. The value of an object name in the JSON document that exists in the collection of object names will be declared as non-string value, which is not surrounded by double quotes.

For example, consider that the property value is not set and the JSON document is { ..., "anumber":"12", ... }. If the property value is set to contain "anumber" then the JSON document would be { ..., "anumber":12, ... }.

The default value is an empty collection.

See Also:
Constant Field Values

JSON_ATTRS_AS_ELEMS

@Deprecated
public static final java.lang.String JSON_ATTRS_AS_ELEMS
Deprecated. 
JSON attributes as elements property is now deprecated. See JSONConfiguration. This property is valid for the JSONNotation.MAPPED notation only.

The type of this property is Collection<String>.

The value is a collection of string values that are object names that correspond to XML attribute information items. The value of an object name in the JSON document that exists in the collection of object names will be declared as an element as not as an attribute if the object corresponds to an XML attribute information item.

For example, consider that the property value is not set and the JSON document is { ..., "@number":"12", ... }. If the property value is set contain "number" then the JSON document would be { ..., "number":"12", ... }.

The default value is an empty collection.

See Also:
Constant Field Values

JSON_XML2JSON_NS

@Deprecated
public static final java.lang.String JSON_XML2JSON_NS
Deprecated. 
XML to JSON namespace mapping property is now deprecated. See JSONConfiguration. This property is valid for the MAPPED_JETTISON notation only.

The type of this property is Map<String,String>.

The value is a map with zero or more key/value pairs, where the key is an XML namespace and the value is the prefix to use as the replacement for the XML namespace.

The default value is a map with zero key/value pairs.

See Also:
Constant Field Values
Constructor Detail

JSONJAXBContext

public JSONJAXBContext(java.lang.Class... classesToBeBound)
                throws javax.xml.bind.JAXBException
Constructs a new instance with default JSONConfiguration.

Parameters:
classesToBeBound - list of java classes to be recognized by the new JSONJAXBContext. Can be empty, in which case a JSONJAXBContext that only knows about spec-defined classes will be returned.
Throws:
javax.xml.bind.JAXBException - if an error was encountered while creating the underlying JAXBContext.

JSONJAXBContext

public JSONJAXBContext(JSONConfiguration config,
                       java.lang.Class... classesToBeBound)
                throws javax.xml.bind.JAXBException
Constructs a new instance with given JSONConfiguration.

Parameters:
config - JSONConfiguration, can not be null
classesToBeBound - list of java classes to be recognized by the new JSONJAXBContext. Can be empty, in which case a JSONJAXBContext that only knows about spec-defined classes will be returned.
Throws:
javax.xml.bind.JAXBException - if an error was encountered while creating the underlying JAXBContext.

JSONJAXBContext

public JSONJAXBContext(java.lang.Class[] classesToBeBound,
                       java.util.Map<java.lang.String,java.lang.Object> properties)
                throws javax.xml.bind.JAXBException
Constructs a new instance with a custom set of properties. The default JSONConfiguration is used if no (now deprecated) JSON related properties are specified

Parameters:
classesToBeBound - list of java classes to be recognized by the new JSONJAXBContext. Can be empty, in which case a JSONJAXBContext that only knows about spec-defined classes will be returned.
properties - the custom set of properties. If it contains(now deprecated) JSON related properties, then a non-default JSONConfiguration is used reflecting the JSON properties
Throws:
javax.xml.bind.JAXBException - if an error was encountered while creating the underlying JAXBContext.

JSONJAXBContext

public JSONJAXBContext(JSONConfiguration config,
                       java.lang.Class[] classesToBeBound,
                       java.util.Map<java.lang.String,java.lang.Object> properties)
                throws javax.xml.bind.JAXBException
Constructs a new instance with a custom set of properties. If no (now deprecated) JSON related properties are specified, the JSONConfiguration.DEFAULT is used as JSONConfiguration

Parameters:
config - JSONConfiguration, can not be null
classesToBeBound - list of java classes to be recognized by the new JSONJAXBContext. Can be empty, in which case a JSONJAXBContext that only knows about spec-defined classes will be returned.
properties - the custom set of properties.
Throws:
javax.xml.bind.JAXBException - if an error was encountered while creating the underlying JAXBContext.

JSONJAXBContext

public JSONJAXBContext(java.lang.String contextPath)
                throws javax.xml.bind.JAXBException
Construct a new instance of using context class loader of the thread with default JSONConfiguration.

Parameters:
contextPath - list of java package names that contain schema derived class and/or java to schema (JAXB-annotated) mapped classes
Throws:
javax.xml.bind.JAXBException - if an error was encountered while creating the underlying JAXBContext.

JSONJAXBContext

public JSONJAXBContext(JSONConfiguration config,
                       java.lang.String contextPath)
                throws javax.xml.bind.JAXBException
Construct a new instance of using context class loader of the thread with given JSONConfiguration.

Parameters:
config - JSONConfiguration, can not be null
contextPath - list of java package names that contain schema derived class and/or java to schema (JAXB-annotated) mapped classes
Throws:
javax.xml.bind.JAXBException - if an error was encountered while creating the underlying JAXBContext.

JSONJAXBContext

public JSONJAXBContext(java.lang.String contextPath,
                       java.lang.ClassLoader classLoader)
                throws javax.xml.bind.JAXBException
Construct a new instance using a specified class loader with default JSONConfiguration.

Parameters:
contextPath - list of java package names that contain schema derived class and/or java to schema (JAXB-annotated) mapped classes
classLoader -
Throws:
javax.xml.bind.JAXBException - if an error was encountered while creating the underlying JAXBContext.

JSONJAXBContext

public JSONJAXBContext(java.lang.String contextPath,
                       java.lang.ClassLoader classLoader,
                       java.util.Map<java.lang.String,java.lang.Object> properties)
                throws javax.xml.bind.JAXBException
Construct a new instance using a specified class loader and a custom set of properties. JSONConfiguration is set to default, if user does not specify any (now deprecated) JSON related properties

Parameters:
contextPath - list of java package names that contain schema derived class and/or java to schema (JAXB-annotated) mapped classes
classLoader -
properties - the custom set of properties.
Throws:
javax.xml.bind.JAXBException - if an error was encountered while creating the underlying JAXBContext.

JSONJAXBContext

public JSONJAXBContext(JSONConfiguration config,
                       java.lang.String contextPath,
                       java.lang.ClassLoader classLoader,
                       java.util.Map<java.lang.String,java.lang.Object> properties)
                throws javax.xml.bind.JAXBException
Construct a new instance using a specified class loader, set of properties and JSONConfiguration .

Parameters:
config - JSONConfiguration, can not be null
contextPath - list of java package names that contain schema derived class and/or java to schema (JAXB-annotated) mapped classes
classLoader -
properties - the custom set of properties.
Throws:
javax.xml.bind.JAXBException - if an error was encountered while creating the underlying JAXBContext.
Method Detail

getJSONMarshaller

public static JSONMarshaller getJSONMarshaller(javax.xml.bind.Marshaller marshaller)
Get a JSONMarshaller from a Marshaller.

Parameters:
marshaller - the JAXB marshaller.
Returns:
the JSON marshaller.

getJSONUnmarshaller

public static JSONUnmarshaller getJSONUnmarshaller(javax.xml.bind.Unmarshaller unmarshaller)
Get a JSONUnmarshaller from a Unmarshaller.

Parameters:
unmarshaller - the JAXB unmarshaller.
Returns:
the JSON unmarshaller.

getJSONConfiguration

public JSONConfiguration getJSONConfiguration()
Get the JSON configuration.

Specified by:
getJSONConfiguration in interface JSONConfigurated
Returns:
the JSON configuration.

createJSONUnmarshaller

public JSONUnmarshaller createJSONUnmarshaller()
                                        throws javax.xml.bind.JAXBException
Create a JSON unmarshaller.

Returns:
the JSON unmarshaller
Throws:
javax.xml.bind.JAXBException - if there is an error creating the unmarshaller.

createJSONMarshaller

public JSONMarshaller createJSONMarshaller()
                                    throws javax.xml.bind.JAXBException
Create a JSON marshaller.

Returns:
the JSON marshaller.
Throws:
javax.xml.bind.JAXBException - if there is an error creating the marshaller.

createUnmarshaller

public javax.xml.bind.Unmarshaller createUnmarshaller()
                                               throws javax.xml.bind.JAXBException
Overrides underlaying createUnmarshaller method and returns an unmarshaller which is capable of JSON deserialization.

Specified by:
createUnmarshaller in class javax.xml.bind.JAXBContext
Returns:
unmarshaller instance with JSON capabilities
Throws:
javax.xml.bind.JAXBException

createMarshaller

public javax.xml.bind.Marshaller createMarshaller()
                                           throws javax.xml.bind.JAXBException
Overrides underlaying createMarshaller method and returns a marshaller which is capable of JSON serialization.

Specified by:
createMarshaller in class javax.xml.bind.JAXBContext
Returns:
marshaller instance with JSON capabilities
Throws:
javax.xml.bind.JAXBException

createValidator

public javax.xml.bind.Validator createValidator()
                                         throws javax.xml.bind.JAXBException
Simply delegates to underlying JAXBContext implementation.

Specified by:
createValidator in class javax.xml.bind.JAXBContext
Returns:
what underlying JAXBContext returns
Throws:
javax.xml.bind.JAXBException


Copyright © 2010 Oracle Corporation. All Rights Reserved.