|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.xml.bind.JAXBContext
com.sun.jersey.api.json.JSONJAXBContext
public final class JSONJAXBContext
An adaption of JAXBContext
that supports marshalling
and unmarshalling of JAXB beans using the JSON format.
The JSON format may be configured by setting properties on this class when it is constructed and on properties of the Marshaller and Unmarshaller returned from the relevant methods on this class.
To enable JSON marshalling and unmarshalling it is necessary to set
the JSON_ENABLED
property to true
on the Marshaller
and Unmarshaller returned from the relevant methods on this class.
Nested Class Summary | |
---|---|
static class |
JSONJAXBContext.JSONNotation
Enumeration of supported JSON notations. |
Field Summary | |
---|---|
static java.lang.String |
JSON_ARRAYS
JSON arrays property. |
static java.lang.String |
JSON_ATTRS_AS_ELEMS
JSON attributes as elements property. |
static java.lang.String |
JSON_ENABLED
JSON enabled property. |
static java.lang.String |
JSON_NON_STRINGS
JSON non-string values property. |
static java.lang.String |
JSON_NOTATION
JSON notation property. |
static java.lang.String |
JSON_ROOT_UNWRAPPING
XML root element unwrapping. |
static java.lang.String |
JSON_XML2JSON_NS
XML to JSON namespace mapping. |
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 instance with default properties. |
|
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(java.lang.String contextPath)
Construct a new instance of using context class loader of the thread with default properties. |
|
JSONJAXBContext(java.lang.String contextPath,
java.lang.ClassLoader classLoader)
Construct a new instance using a specified class loader with default properties. |
|
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 | |
---|---|
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 |
---|
public static final java.lang.String NAMESPACE
public static final java.lang.String JSON_NOTATION
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
.
public static final java.lang.String JSON_ENABLED
The type of this property is Boolean
If set to true, JSON will be serialized/deserialized instead of XML
The default value is false.
public static final java.lang.String JSON_ROOT_UNWRAPPING
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.
public static final java.lang.String JSON_ARRAYS
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 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.
public static final java.lang.String JSON_NON_STRINGS
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 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.
public static final java.lang.String JSON_ATTRS_AS_ELEMS
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 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.
public static final java.lang.String JSON_XML2JSON_NS
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.
Constructor Detail |
---|
public JSONJAXBContext(java.lang.Class... classesToBeBound) throws javax.xml.bind.JAXBException
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.
javax.xml.bind.JAXBException
- if an error was encountered while creating the
underlying JAXBContext.public JSONJAXBContext(java.lang.Class[] classesToBeBound, java.util.Map<java.lang.String,java.lang.Object> properties) throws javax.xml.bind.JAXBException
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.
javax.xml.bind.JAXBException
- if an error was encountered while creating the
underlying JAXBContext.public JSONJAXBContext(java.lang.String contextPath) throws javax.xml.bind.JAXBException
contextPath
- list of java package names that contain schema
derived class and/or java to schema (JAXB-annotated) mapped
classes
javax.xml.bind.JAXBException
- if an error was encountered while creating the
underlying JAXBContext.public JSONJAXBContext(java.lang.String contextPath, java.lang.ClassLoader classLoader) throws javax.xml.bind.JAXBException
contextPath
- list of java package names that contain schema
derived class and/or java to schema (JAXB-annotated) mapped
classesclassLoader
-
javax.xml.bind.JAXBException
- if an error was encountered while creating the
underlying JAXBContext.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
contextPath
- list of java package names that contain schema
derived class and/or java to schema (JAXB-annotated) mapped
classesclassLoader
- properties
- the custom set of properties.
javax.xml.bind.JAXBException
- if an error was encountered while creating the
underlying JAXBContext.Method Detail |
---|
public javax.xml.bind.Unmarshaller createUnmarshaller() throws javax.xml.bind.JAXBException
createUnmarshaller
in class javax.xml.bind.JAXBContext
javax.xml.bind.JAXBException
public javax.xml.bind.Marshaller createMarshaller() throws javax.xml.bind.JAXBException
createMarshaller
in class javax.xml.bind.JAXBContext
javax.xml.bind.JAXBException
public javax.xml.bind.Validator createValidator() throws javax.xml.bind.JAXBException
createValidator
in class javax.xml.bind.JAXBContext
javax.xml.bind.JAXBException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |