javax.xml.bind

Class JAXB


  • public final class JAXB
    extends Object
    Class that defines convenience methods for common, simple use of JAXB.

    Methods defined in this class are convenience methods that combine several basic operations in the JAXBContext, Unmarshaller, and Marshaller. They are designed to be the prefered methods for developers new to JAXB. They have the following characterstics:

    1. Generally speaking, the performance is not necessarily optimal. It is expected that people who need to write performance critical code will use the rest of the JAXB API directly.
    2. Errors that happen during the processing is wrapped into DataBindingException (which will have JAXBException as its cause. It is expected that people who prefer the checked exception would use the rest of the JAXB API directly.

    In addition, the unmarshal methods have the following characteristic:

    1. Schema validation is not performed on the input XML. The processing will try to continue even if there are errors in the XML, as much as possible. Only as the last resort, this method fails with DataBindingException.

    Similarly, the marshal methods have the following characteristic:

    1. The processing will try to continue even if the Java object tree does not meet the validity requirement. Only as the last resort, this method fails with DataBindingException.

    All the methods on this class require non-null arguments to all parameters. The unmarshal methods either fail with an exception or return a non-null value.

    Since:
    2.1
    • Method Detail

      • unmarshal

        public static <T> T unmarshal(File xml,
                      Class<T> type)
        Reads in a Java object tree from the given XML input.
        Parameters:
        xml - Reads the entire file as XML.
      • unmarshal

        public static <T> T unmarshal(URL xml,
                      Class<T> type)
        Reads in a Java object tree from the given XML input.
        Parameters:
        xml - The resource pointed by the URL is read in its entirety.
      • unmarshal

        public static <T> T unmarshal(URI xml,
                      Class<T> type)
        Reads in a Java object tree from the given XML input.
        Parameters:
        xml - The URI is turned into URL and then follows the handling of URL.
      • unmarshal

        public static <T> T unmarshal(String xml,
                      Class<T> type)
        Reads in a Java object tree from the given XML input.
        Parameters:
        xml - The string is first interpreted as an absolute URI. If it's not a valid absolute URI, then it's interpreted as a File
      • unmarshal

        public static <T> T unmarshal(InputStream xml,
                      Class<T> type)
        Reads in a Java object tree from the given XML input.
        Parameters:
        xml - The entire stream is read as an XML infoset. Upon a successful completion, the stream will be closed by this method.
      • unmarshal

        public static <T> T unmarshal(Reader xml,
                      Class<T> type)
        Reads in a Java object tree from the given XML input.
        Parameters:
        xml - The character stream is read as an XML infoset. The encoding declaration in the XML will be ignored. Upon a successful completion, the stream will be closed by this method.
      • unmarshal

        public static <T> T unmarshal(Source xml,
                      Class<T> type)
        Reads in a Java object tree from the given XML input.
        Parameters:
        xml - The XML infoset that the Source represents is read.
      • marshal

        public static void marshal(Object jaxbObject,
                   File xml)
        Writes a Java object tree to XML and store it to the specified location.
        Parameters:
        jaxbObject - The Java object to be marshalled into XML. If this object is a JAXBElement, it will provide the root tag name and the body. If this object has XmlRootElement on its class definition, that will be used as the root tag name and the given object will provide the body. Otherwise, the root tag name is infered from the short class name. This parameter must not be null.
        xml - XML will be written to this file. If it already exists, it will be overwritten.
        Throws:
        DataBindingException - If the operation fails, such as due to I/O error, unbindable classes.
      • marshal

        public static void marshal(Object jaxbObject,
                   URL xml)
        Writes a Java object tree to XML and store it to the specified location.
        Parameters:
        jaxbObject - The Java object to be marshalled into XML. If this object is a JAXBElement, it will provide the root tag name and the body. If this object has XmlRootElement on its class definition, that will be used as the root tag name and the given object will provide the body. Otherwise, the root tag name is infered from the short class name. This parameter must not be null.
        xml - The XML will be sent to the resource pointed by this URL. Note that not all URLs support such operation, and exact semantics depends on the URL implementations. In case of HTTP URLs, this will perform HTTP POST.
        Throws:
        DataBindingException - If the operation fails, such as due to I/O error, unbindable classes.
      • marshal

        public static void marshal(Object jaxbObject,
                   URI xml)
        Writes a Java object tree to XML and store it to the specified location.
        Parameters:
        jaxbObject - The Java object to be marshalled into XML. If this object is a JAXBElement, it will provide the root tag name and the body. If this object has XmlRootElement on its class definition, that will be used as the root tag name and the given object will provide the body. Otherwise, the root tag name is infered from the short class name. This parameter must not be null.
        xml - The URI is turned into URL and then follows the handling of URL. See above.
        Throws:
        DataBindingException - If the operation fails, such as due to I/O error, unbindable classes.
      • marshal

        public static void marshal(Object jaxbObject,
                   String xml)
        Writes a Java object tree to XML and store it to the specified location.
        Parameters:
        jaxbObject - The Java object to be marshalled into XML. If this object is a JAXBElement, it will provide the root tag name and the body. If this object has XmlRootElement on its class definition, that will be used as the root tag name and the given object will provide the body. Otherwise, the root tag name is infered from the short class name. This parameter must not be null.
        xml - The string is first interpreted as an absolute URI. If it's not a valid absolute URI, then it's interpreted as a File
        Throws:
        DataBindingException - If the operation fails, such as due to I/O error, unbindable classes.
      • marshal

        public static void marshal(Object jaxbObject,
                   OutputStream xml)
        Writes a Java object tree to XML and store it to the specified location.
        Parameters:
        jaxbObject - The Java object to be marshalled into XML. If this object is a JAXBElement, it will provide the root tag name and the body. If this object has XmlRootElement on its class definition, that will be used as the root tag name and the given object will provide the body. Otherwise, the root tag name is infered from the short class name. This parameter must not be null.
        xml - The XML will be sent to the given OutputStream. Upon a successful completion, the stream will be closed by this method.
        Throws:
        DataBindingException - If the operation fails, such as due to I/O error, unbindable classes.
      • marshal

        public static void marshal(Object jaxbObject,
                   Writer xml)
        Writes a Java object tree to XML and store it to the specified location.
        Parameters:
        jaxbObject - The Java object to be marshalled into XML. If this object is a JAXBElement, it will provide the root tag name and the body. If this object has XmlRootElement on its class definition, that will be used as the root tag name and the given object will provide the body. Otherwise, the root tag name is infered from the short class name. This parameter must not be null.
        xml - The XML will be sent as a character stream to the given Writer. Upon a successful completion, the stream will be closed by this method.
        Throws:
        DataBindingException - If the operation fails, such as due to I/O error, unbindable classes.
      • marshal

        public static void marshal(Object jaxbObject,
                   Result xml)
        Writes a Java object tree to XML and store it to the specified location.
        Parameters:
        jaxbObject - The Java object to be marshalled into XML. If this object is a JAXBElement, it will provide the root tag name and the body. If this object has XmlRootElement on its class definition, that will be used as the root tag name and the given object will provide the body. Otherwise, the root tag name is infered from the short class name. This parameter must not be null.
        xml - The XML will be sent to the Result object.
        Throws:
        DataBindingException - If the operation fails, such as due to I/O error, unbindable classes.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-javax/xml/bind/JAXB.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : https://docs.oracle.com

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut