Class JettisonJaxbContext

  • All Implemented Interfaces:
    JettisonConfigured

    public final class JettisonJaxbContext
    extends jakarta.xml.bind.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.

    • Constructor Detail

      • JettisonJaxbContext

        public JettisonJaxbContext​(Class... classesToBeBound)
                            throws jakarta.xml.bind.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:
        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 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:
        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 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:
        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, 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:
        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 default JettisonConfig.
        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 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:
        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 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:
        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. 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:
        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 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:
        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 a JettisonMarshaller from a Marshaller.
        Parameters:
        marshaller - the JAXB marshaller.
        Returns:
        the JSON marshaller.
      • getJSONUnmarshaller

        public static JettisonUnmarshaller getJSONUnmarshaller​(jakarta.xml.bind.Unmarshaller unmarshaller)
        Get a JettisonUnmarshaller from a Unmarshaller.
        Parameters:
        unmarshaller - the JAXB unmarshaller.
        Returns:
        the JSON unmarshaller.
      • 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.JAXBException
        Overrides underlying createUnmarshaller method and returns an unmarshaller which is capable of JSON deserialization.
        Specified by:
        createUnmarshaller in class jakarta.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.JAXBException
        Overrides underlaying createMarshaller method and returns a marshaller which is capable of JSON serialization.
        Specified by:
        createMarshaller in class jakarta.xml.bind.JAXBContext
        Returns:
        marshaller instance with JSON capabilities
        Throws:
        jakarta.xml.bind.JAXBException