Class JiBXUtil

java.lang.Object
org.dellroad.stuff.jibx.JiBXUtil

public final class JiBXUtil extends Object
Some simplified API methods for JiBX XML encoding/decoding.
  • Field Details

  • Method Details

    • readObject

      public static <T> T readObject(Class<T> targetClass, InputStream input) throws JiBXException, IOException
      Read in an object encoded as XML. This method assumes there is exactly one binding for the given class.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      The input is not closed by this method.

      Type Parameters:
      T - type of object to read
      Parameters:
      targetClass - target class
      input - source for the XML document
      Returns:
      decoded object
      Throws:
      JiBXException - if there is a JiBX parse error
      IOException - if an error occurs reading from input
    • readObject

      public static <T> T readObject(Class<T> targetClass, String bindingName, InputStream input) throws JiBXException, IOException
      Read in an object encoded as XML.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      The input is not closed by this method.

      Type Parameters:
      T - type of object to read
      Parameters:
      targetClass - target class
      bindingName - binding name, or null to choose the only one
      input - source for the XML document
      Returns:
      decoded object
      Throws:
      JiBXException - if there is a JiBX parse error
      IOException - if an error occurs reading from input
    • readObject

      public static <T> T readObject(Class<T> targetClass, Reader input) throws JiBXException, IOException
      Read in an object encoded as XML. This method assumes there is exactly one binding for the given class.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      The input is not closed by this method.

      Type Parameters:
      T - type of object to read
      Parameters:
      targetClass - target class
      input - source for the XML document
      Returns:
      decoded object
      Throws:
      JiBXException - if there is a JiBX parse error
      IOException - if an error occurs reading from input
    • readObject

      public static <T> T readObject(Class<T> targetClass, String bindingName, Reader input) throws JiBXException, IOException
      Read in an object encoded as XML.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      The input is not closed by this method.

      Type Parameters:
      T - type of object to read
      Parameters:
      targetClass - target class
      bindingName - binding name, or null to choose the only one
      input - source for the XML document
      Returns:
      decoded object
      Throws:
      JiBXException - if there is a JiBX parse error
      IOException - if an error occurs reading from input
    • readObject

      public static <T> T readObject(Class<T> targetClass, URL url) throws JiBXException, IOException
      Read in an object encoded as XML from an URL. This method assumes there is exactly one binding for the given class.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      Type Parameters:
      T - type of object to read
      Parameters:
      targetClass - target class
      url - source for the XML document
      Returns:
      decoded object
      Throws:
      JiBXException - if there is a JiBX parse error
      IOException - if an error occurs reading the referenced document
    • readObject

      public static <T> T readObject(Class<T> targetClass, String bindingName, URL url) throws JiBXException, IOException
      Read in an object encoded as XML from an URL.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      Type Parameters:
      T - type of object to read
      Parameters:
      targetClass - target class
      url - source for the XML document
      bindingName - binding name, or null to choose the only one
      Returns:
      decoded object
      Throws:
      JiBXException - if there is a JiBX parse error
      IOException - if an error occurs reading the referenced document
    • writeObject

      public static <T> void writeObject(T obj, OutputStream output) throws JiBXException, IOException
      Write out the given instance encoded as a UTF-8 encoded XML document. This method assumes there is exactly one binding for the given class.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      Type Parameters:
      T - object type
      Parameters:
      obj - object to write
      output - output destination; will not be closed by this method
      Throws:
      JiBXException - if there is a JiBX encoding error
      IOException - if an error occurs writing to output
    • writeObject

      public static <T> void writeObject(T obj, String bindingName, OutputStream output) throws JiBXException, IOException
      Write out the given instance encoded as a UTF-8 encoded XML document.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      Type Parameters:
      T - object type
      Parameters:
      obj - object to write
      bindingName - binding name, or null to choose the only one
      output - output destination; will not be closed by this method
      Throws:
      JiBXException - if there is a JiBX encoding error
      IOException - if an error occurs writing to output
    • writeObject

      public static <T> void writeObject(T obj, Writer writer) throws JiBXException, IOException
      Write out the given instance encoded as an XML document with "UTF-8" as the declared encoding. This method assumes there is exactly one binding for the given class.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      Type Parameters:
      T - object type
      Parameters:
      obj - object to write
      writer - output destination; will not be closed by this method
      Throws:
      JiBXException - if there is a JiBX encoding error
      IOException - if an error occurs writing to writer
    • writeObject

      public static void writeObject(Object obj, String bindingName, Writer writer) throws JiBXException, IOException
      Write out the given instance encoded as an XML document with "UTF-8" as the declared encoding.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      Parameters:
      obj - object to write
      bindingName - binding name, or null to choose the only one
      writer - output destination; will not be closed by this method
      Throws:
      JiBXException - if there is a JiBX encoding error
      IOException - if an error occurs writing to writer
    • toString

      public static String toString(Object obj) throws JiBXException
      Encode the given instance as an XML document and return it as a String. This method assumes there is exactly one binding for the given class.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      Parameters:
      obj - object to encode
      Returns:
      XML encoding of obj
      Throws:
      JiBXException - if there is a JiBX encoding error
    • toString

      public static String toString(Object obj, String bindingName) throws JiBXException
      Encode the given instance as an XML document and return it as a String.

      This method runs within a new invocation of IdGenerator.run() to support object references (see IdMapper).

      Parameters:
      obj - object to encode
      bindingName - binding name, or null to choose the only one
      Returns:
      XML encoding of obj
      Throws:
      JiBXException - if there is a JiBX encoding error