org.glassfish.jersey.jettison
Class JettisonJaxbContext

java.lang.Object
  extended by javax.xml.bind.JAXBContext
      extended by org.glassfish.jersey.jettison.JettisonJaxbContext
All Implemented Interfaces:
JettisonConfigured

public final class JettisonJaxbContext
extends JAXBContext
implements JettisonConfigured

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 JettisonConfig object as a constructor parameter of this class.


Field Summary
 
Fields inherited from class javax.xml.bind.JAXBContext
JAXB_CONTEXT_FACTORY
 
Constructor Summary
JettisonJaxbContext(Class... classesToBeBound)
          Constructs a new instance with default JettisonConfig.
JettisonJaxbContext(Class[] classesToBeBound, Map<String,Object> properties)
          Constructs a new instance with a custom set of properties.
JettisonJaxbContext(JettisonConfig config, Class... classesToBeBound)
          Constructs a new instance with given JettisonConfig.
JettisonJaxbContext(JettisonConfig config, Class[] classesToBeBound, Map<String,Object> properties)
          Constructs a new instance with a custom set of properties.
JettisonJaxbContext(JettisonConfig config, String contextPath)
          Construct a new instance of using context class loader of the thread with given JettisonConfig.
JettisonJaxbContext(JettisonConfig config, String contextPath, ClassLoader classLoader, Map<String,Object> properties)
          Construct a new instance using a specified class loader, set of properties and JettisonConfig .
JettisonJaxbContext(String contextPath)
          Construct a new instance of using context class loader of the thread with default JettisonConfig.
JettisonJaxbContext(String contextPath, ClassLoader classLoader)
          Construct a new instance using a specified class loader with default JettisonConfig.
JettisonJaxbContext(String contextPath, ClassLoader classLoader, Map<String,Object> properties)
          Construct a new instance using a specified class loader and a custom set of properties.
 
Method Summary
 JettisonMarshaller createJsonMarshaller()
          Create a JSON marshaller.
 JettisonUnmarshaller createJsonUnmarshaller()
          Create a JSON unmarshaller.
 Marshaller createMarshaller()
          Overrides underlaying createMarshaller method and returns a marshaller which is capable of JSON serialization.
 Unmarshaller createUnmarshaller()
          Overrides underlying createUnmarshaller method and returns an unmarshaller which is capable of JSON deserialization.
 Validator createValidator()
          Simply delegates to underlying JAXBContext implementation.
 JettisonConfig getJSONConfiguration()
          Get the JSON configuration.
static JettisonMarshaller getJSONMarshaller(Marshaller marshaller)
          Get a JettisonMarshaller from a Marshaller.
static JettisonUnmarshaller getJSONUnmarshaller(Unmarshaller unmarshaller)
          Get a JettisonUnmarshaller 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
 

Constructor Detail

JettisonJaxbContext

public JettisonJaxbContext(Class... classesToBeBound)
                    throws JAXBException
Constructs a new instance with default JettisonConfig.

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:
JAXBException - if an error was encountered while creating the underlying JAXBContext.

JettisonJaxbContext

public JettisonJaxbContext(JettisonConfig config,
                           Class... classesToBeBound)
                    throws JAXBException
Constructs a new instance with given JettisonConfig.

Parameters:
config - JettisonConfig, 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:
JAXBException - if an error was encountered while creating the underlying JAXBContext.

JettisonJaxbContext

public JettisonJaxbContext(Class[] classesToBeBound,
                           Map<String,Object> properties)
                    throws JAXBException
Constructs a new instance with a custom set of properties. The default JettisonConfig 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 JettisonConfig is used reflecting the JSON properties
Throws:
JAXBException - if an error was encountered while creating the underlying JAXBContext.

JettisonJaxbContext

public JettisonJaxbContext(JettisonConfig config,
                           Class[] classesToBeBound,
                           Map<String,Object> properties)
                    throws JAXBException
Constructs a new instance with a custom set of properties. If no (now deprecated) JSON related properties are specified, the JettisonConfig.DEFAULT is used as JettisonConfig

Parameters:
config - JettisonConfig, 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:
JAXBException - if an error was encountered while creating the underlying JAXBContext.

JettisonJaxbContext

public JettisonJaxbContext(String contextPath)
                    throws JAXBException
Construct a new instance of using context class loader of the thread with default JettisonConfig.

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

JettisonJaxbContext

public JettisonJaxbContext(JettisonConfig config,
                           String contextPath)
                    throws JAXBException
Construct a new instance of using context class loader of the thread with given JettisonConfig.

Parameters:
config - JettisonConfig, 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:
JAXBException - if an error was encountered while creating the underlying JAXBContext.

JettisonJaxbContext

public JettisonJaxbContext(String contextPath,
                           ClassLoader classLoader)
                    throws JAXBException
Construct a new instance using a specified class loader with default JettisonConfig.

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

JettisonJaxbContext

public JettisonJaxbContext(String contextPath,
                           ClassLoader classLoader,
                           Map<String,Object> properties)
                    throws JAXBException
Construct a new instance using a specified class loader and a custom set of properties. JettisonConfig 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:
JAXBException - if an error was encountered while creating the underlying JAXBContext.

JettisonJaxbContext

public JettisonJaxbContext(JettisonConfig config,
                           String contextPath,
                           ClassLoader classLoader,
                           Map<String,Object> properties)
                    throws JAXBException
Construct a new instance using a specified class loader, set of properties and JettisonConfig .

Parameters:
config - JettisonConfig, 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:
JAXBException - if an error was encountered while creating the underlying JAXBContext.
Method Detail

getJSONMarshaller

public static JettisonMarshaller getJSONMarshaller(Marshaller marshaller)
Get a JettisonMarshaller from a Marshaller.

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

getJSONUnmarshaller

public static JettisonUnmarshaller getJSONUnmarshaller(Unmarshaller unmarshaller)
Get a JettisonUnmarshaller from a Unmarshaller.

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

getJSONConfiguration

public JettisonConfig getJSONConfiguration()
Get the JSON configuration.

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

createJsonUnmarshaller

public JettisonUnmarshaller createJsonUnmarshaller()
                                            throws JAXBException
Create a JSON unmarshaller.

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

createJsonMarshaller

public JettisonMarshaller createJsonMarshaller()
                                        throws JAXBException
Create a JSON marshaller.

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

createUnmarshaller

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

Specified by:
createUnmarshaller in class JAXBContext
Returns:
unmarshaller instance with JSON capabilities
Throws:
JAXBException

createMarshaller

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

Specified by:
createMarshaller in class JAXBContext
Returns:
marshaller instance with JSON capabilities
Throws:
JAXBException

createValidator

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

Specified by:
createValidator in class JAXBContext
Returns:
what underlying JAXBContext returns
Throws:
JAXBException


Copyright © 2007-2013, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.