Package org.glassfish.jersey.jettison
Class JettisonJaxbContext
- java.lang.Object
-
- jakarta.xml.bind.JAXBContext
-
- org.glassfish.jersey.jettison.JettisonJaxbContext
-
- All Implemented Interfaces:
JettisonConfigured
public final class JettisonJaxbContext extends jakarta.xml.bind.JAXBContext implements JettisonConfigured
An adaption ofJAXBContextthat supports marshalling and unmarshalling of JAXB beans using the JSON format.The JSON format may be configured by using a
JettisonConfigobject as a constructor parameter of this class.
-
-
Constructor Summary
Constructors Constructor Description JettisonJaxbContext(Class... classesToBeBound)Constructs a new instance with defaultJettisonConfig.JettisonJaxbContext(Class[] classesToBeBound, Map<String,Object> properties)Constructs a new instance with a custom set of properties.JettisonJaxbContext(String contextPath)Construct a new instance of using context class loader of the thread with defaultJettisonConfig.JettisonJaxbContext(String contextPath, ClassLoader classLoader)Construct a new instance using a specified class loader with defaultJettisonConfig.JettisonJaxbContext(String contextPath, ClassLoader classLoader, Map<String,Object> properties)Construct a new instance using a specified class loader and a custom set of properties.JettisonJaxbContext(JettisonConfig config, Class... classesToBeBound)Constructs a new instance with givenJettisonConfig.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 givenJettisonConfig.JettisonJaxbContext(JettisonConfig config, String contextPath, ClassLoader classLoader, Map<String,Object> properties)Construct a new instance using a specified class loader, set of properties andJettisonConfig.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description JettisonMarshallercreateJsonMarshaller()Create a JSON marshaller.JettisonUnmarshallercreateJsonUnmarshaller()Create a JSON unmarshaller.jakarta.xml.bind.MarshallercreateMarshaller()Overrides underlaying createMarshaller method and returns a marshaller which is capable of JSON serialization.jakarta.xml.bind.UnmarshallercreateUnmarshaller()Overrides underlying createUnmarshaller method and returns an unmarshaller which is capable of JSON deserialization.JettisonConfiggetJSONConfiguration()Get the JSON configuration.static JettisonMarshallergetJSONMarshaller(jakarta.xml.bind.Marshaller marshaller)Get aJettisonMarshallerfrom aMarshaller.static JettisonUnmarshallergetJSONUnmarshaller(jakarta.xml.bind.Unmarshaller unmarshaller)Get aJettisonUnmarshallerfrom aUnmarshaller.
-
-
-
Constructor Detail
-
JettisonJaxbContext
public JettisonJaxbContext(Class... classesToBeBound) throws jakarta.xml.bind.JAXBException
Constructs a new instance with defaultJettisonConfig.- 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:
jakarta.xml.bind.JAXBException- if an error was encountered while creating the underlying JAXBContext.
-
JettisonJaxbContext
public JettisonJaxbContext(JettisonConfig config, Class... classesToBeBound) throws jakarta.xml.bind.JAXBException
Constructs a new instance with givenJettisonConfig.- Parameters:
config-JettisonConfig, can not be nullclassesToBeBound- 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:
jakarta.xml.bind.JAXBException- if an error was encountered while creating the underlying JAXBContext.
-
JettisonJaxbContext
public JettisonJaxbContext(Class[] classesToBeBound, Map<String,Object> properties) throws jakarta.xml.bind.JAXBException
Constructs a new instance with a custom set of properties. The defaultJettisonConfigis 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-defaultJettisonConfigis used reflecting the JSON properties- Throws:
jakarta.xml.bind.JAXBException- if an error was encountered while creating the underlying JAXBContext.
-
JettisonJaxbContext
public JettisonJaxbContext(JettisonConfig config, Class[] classesToBeBound, Map<String,Object> properties) throws jakarta.xml.bind.JAXBException
Constructs a new instance with a custom set of properties. If no (now deprecated) JSON related properties are specified, theJettisonConfig.DEFAULTis used asJettisonConfig- Parameters:
config-JettisonConfig, can not be nullclassesToBeBound- 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:
jakarta.xml.bind.JAXBException- if an error was encountered while creating the underlying JAXBContext.
-
JettisonJaxbContext
public JettisonJaxbContext(String contextPath) throws jakarta.xml.bind.JAXBException
Construct a new instance of using context class loader of the thread with defaultJettisonConfig.- Parameters:
contextPath- list of java package names that contain schema derived class and/or java to schema (JAXB-annotated) mapped classes- Throws:
jakarta.xml.bind.JAXBException- if an error was encountered while creating the underlying JAXBContext.
-
JettisonJaxbContext
public JettisonJaxbContext(JettisonConfig config, String contextPath) throws jakarta.xml.bind.JAXBException
Construct a new instance of using context class loader of the thread with givenJettisonConfig.- Parameters:
config-JettisonConfig, can not be nullcontextPath- list of java package names that contain schema derived class and/or java to schema (JAXB-annotated) mapped classes- Throws:
jakarta.xml.bind.JAXBException- if an error was encountered while creating the underlying JAXBContext.
-
JettisonJaxbContext
public JettisonJaxbContext(String contextPath, ClassLoader classLoader) throws jakarta.xml.bind.JAXBException
Construct a new instance using a specified class loader with defaultJettisonConfig.- Parameters:
contextPath- list of java package names that contain schema derived class and/or java to schema (JAXB-annotated) mapped classesclassLoader-- Throws:
jakarta.xml.bind.JAXBException- if an error was encountered while creating the underlying JAXBContext.
-
JettisonJaxbContext
public JettisonJaxbContext(String contextPath, ClassLoader classLoader, Map<String,Object> properties) throws jakarta.xml.bind.JAXBException
Construct a new instance using a specified class loader and a custom set of properties.JettisonConfigis 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 classesclassLoader-properties- the custom set of properties.- Throws:
jakarta.xml.bind.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 jakarta.xml.bind.JAXBException
Construct a new instance using a specified class loader, set of properties andJettisonConfig.- Parameters:
config-JettisonConfig, can not be nullcontextPath- 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.- Throws:
jakarta.xml.bind.JAXBException- if an error was encountered while creating the underlying JAXBContext.
-
-
Method Detail
-
getJSONMarshaller
public static JettisonMarshaller getJSONMarshaller(jakarta.xml.bind.Marshaller marshaller)
Get aJettisonMarshallerfrom aMarshaller.- Parameters:
marshaller- the JAXB marshaller.- Returns:
- the JSON marshaller.
-
getJSONUnmarshaller
public static JettisonUnmarshaller getJSONUnmarshaller(jakarta.xml.bind.Unmarshaller unmarshaller)
Get aJettisonUnmarshallerfrom aUnmarshaller.- Parameters:
unmarshaller- the JAXB unmarshaller.- Returns:
- the JSON unmarshaller.
-
getJSONConfiguration
public JettisonConfig getJSONConfiguration()
Get the JSON configuration.- Specified by:
getJSONConfigurationin interfaceJettisonConfigured- Returns:
- the JSON configuration.
-
createJsonUnmarshaller
public JettisonUnmarshaller createJsonUnmarshaller() throws jakarta.xml.bind.JAXBException
Create a JSON unmarshaller.- Returns:
- the JSON unmarshaller
- Throws:
jakarta.xml.bind.JAXBException- if there is an error creating the unmarshaller.
-
createJsonMarshaller
public JettisonMarshaller createJsonMarshaller() throws jakarta.xml.bind.JAXBException
Create a JSON marshaller.- Returns:
- the JSON marshaller.
- Throws:
jakarta.xml.bind.JAXBException- if there is an error creating the marshaller.
-
createUnmarshaller
public jakarta.xml.bind.Unmarshaller createUnmarshaller() throws jakarta.xml.bind.JAXBExceptionOverrides underlying createUnmarshaller method and returns an unmarshaller which is capable of JSON deserialization.- Specified by:
createUnmarshallerin classjakarta.xml.bind.JAXBContext- Returns:
- unmarshaller instance with JSON capabilities
- Throws:
jakarta.xml.bind.JAXBException
-
createMarshaller
public jakarta.xml.bind.Marshaller createMarshaller() throws jakarta.xml.bind.JAXBExceptionOverrides underlaying createMarshaller method and returns a marshaller which is capable of JSON serialization.- Specified by:
createMarshallerin classjakarta.xml.bind.JAXBContext- Returns:
- marshaller instance with JSON capabilities
- Throws:
jakarta.xml.bind.JAXBException
-
-