com.sun.jersey.api.json
Class JSONJAXBContext

java.lang.Object
  extended by javax.xml.bind.JAXBContext
      extended by com.sun.jersey.api.json.JSONJAXBContext

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

JSONJAXBContext is a configurable JAXBContext wrapper. It allows serialization and deserialization of JAXB beans to and from JSON format. Configuration is done by providing a set of properties to the JSONJAXBContext constructor. The properties could be also set directly on Marshaller/Unmarshaller created by the context.


Nested Class Summary
static class JSONJAXBContext.JSONNotation
           
 
Field Summary
static java.lang.String JSON_ARRAYS
          Expects a list of names in JSON format, which represent arrays, and should be treated as arrays even if they contain just one single element.
static java.lang.String JSON_ENABLED
          If set to true, JSON will be serialized/deserialized instead of XML
static java.lang.String JSON_NON_STRINGS
          Expects a list of names in JSON format, which represent non-string values (such as numbers), and should be serialized out without surrounding double quotes I.e.
static java.lang.String JSON_NOTATION
          Expects a String corresponding to desired JSON notation.
static java.lang.String JSON_ROOT_UNWRAPPING
          If set to true, JSON code corresponding to the XML root element will be stripped out for MAPPED (default) notation.
static java.lang.String JSON_XML2JSON_NS
          Via this property you can configure namespaces mapping used by MAPPED_JETTISON notation.
static java.lang.String NAMESPACE
          A namespace for JSONJAXBContext related properties names.
 
Fields inherited from class javax.xml.bind.JAXBContext
JAXB_CONTEXT_FACTORY
 
Constructor Summary
JSONJAXBContext(java.lang.Class... classesToBeBound)
          Constructs a new JSONJAXBContext with default properties.
JSONJAXBContext(java.lang.Class[] classesToBeBound, java.util.Map<java.lang.String,java.lang.Object> properties)
          Constructs a new JSONJAXBContext with a custom set of properties.
 
Method Summary
 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.
 
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

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

See Also:
Constant Field Values

JSON_NOTATION

public static final java.lang.String JSON_NOTATION
Expects a String corresponding to desired JSON notation. Currently supported notations are "MAPPED", "MAPPED_JETTISON" and "BADGERFISH"

See Also:
Constant Field Values

JSON_ENABLED

public static final java.lang.String JSON_ENABLED
If set to true, JSON will be serialized/deserialized instead of XML

See Also:
Constant Field Values

JSON_ROOT_UNWRAPPING

public static final java.lang.String JSON_ROOT_UNWRAPPING
If set to true, JSON code corresponding to the XML root element will be stripped out for MAPPED (default) notation.

See Also:
Constant Field Values

JSON_ARRAYS

public static final java.lang.String JSON_ARRAYS
Expects a list of names in JSON format, which represent arrays, and should be treated as arrays even if they contain just one single element. I.e. { ..., "arr1":["single element"], ... } would be serialized as { ..., "arr1":"single element", ... }, if JSON_ARRAYS was not set to "[\"arr1\"]" Related to MAPPED notation only.

See Also:
Constant Field Values

JSON_NON_STRINGS

public static final java.lang.String JSON_NON_STRINGS
Expects a list of names in JSON format, which represent non-string values (such as numbers), and should be serialized out without surrounding double quotes I.e. { ..., "anumber":12, ... } would be serialized as { ..., "anumber":"12", ... }, if JSON_NON_STRINGS was not set to "[\"anumber\"]" Related to MAPPED notation only.

See Also:
Constant Field Values

JSON_XML2JSON_NS

public static final java.lang.String JSON_XML2JSON_NS
Via this property you can configure namespaces mapping used by MAPPED_JETTISON notation.

See Also:
Constant Field Values
Constructor Detail

JSONJAXBContext

public JSONJAXBContext(java.lang.Class... classesToBeBound)
                throws javax.xml.bind.JAXBException
Constructs a new JSONJAXBContext with default properties. You will need to set JSON_ENABLED property to true on appropriate Marshaller/Unmarshaller to actually switch JSON on.

Parameters:
classesToBeBound -
Throws:
javax.xml.bind.JAXBException

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 JSONJAXBContext with a custom set of properties.

Parameters:
classesToBeBound -
Throws:
javax.xml.bind.JAXBException
Method Detail

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