public class RdfXml extends CharMarshaller
A pairing of a RdfXmlSerializer and RdfXmlParser into a single class with convenience to/of methods.

The general idea is to combine a single serializer and parser inside a simplified API for serializing and parsing POJOs.

Examples:

// Using instance. RdfXml rdfXml = new RdfXml(); MyPojo myPojo = rdfXml.read(string, MyPojo.class); String string = rdfXml.write(myPojo);

// Using DEFAULT instance. MyPojo myPojo = RdfXml.DEFAULT.read(string, MyPojo.class); String string = RdfXml.DEFAULT.write(myPojo);

Example output (bean with name/age):

<rdf:RDF> <rdf:Description rdf:about="..."> <j:name>Alice</j:name> <j:age>30</j:age> </rdf:Description> </rdf:RDF>

Complex (nested address + array of tags):

<rdf:RDF> <rdf:Description rdf:about="..."> <j:name>Alice</j:name> <j:age>30</j:age> <j:address rdf:resource=".../address"/> <j:tags rdf:resource=".../tags"/> </rdf:Description> <rdf:Description rdf:about=".../address"> <j:street>123 Main St</j:street> <j:city>Boston</j:city> <j:state>MA</j:state> </rdf:Description> </rdf:RDF>

// Using static shortcuts. MyPojo myPojo = RdfXml.to(string, MyPojo.class); String string = RdfXml.of(myPojo);

See Also:
  • Field Details

    • DEFAULT

      public static final RdfXml DEFAULT
      Default reusable instance.
  • Constructor Details

  • Method Details

    • of

      public static String of(Object object) throws SerializeException
      Serializes a POJO to a String using the DEFAULT marshaller.

      A shortcut for calling DEFAULT.write(object).

      Parameters:
      object - The object to serialize.
      Returns:
      The serialized object.
      Throws:
      SerializeException - If a problem occurred trying to convert the output.
    • to

      public static <T> T to(String input, Class<T> type) throws ParseException
      Parses an input into the specified object type using the DEFAULT marshaller.

      A shortcut for calling DEFAULT.read(input, type).

      Type Parameters:
      T - The class type of the object being created.
      Parameters:
      input - The input.
      type - The object type to create.
      Returns:
      The parsed object.
      Throws:
      ParseException - Malformed input encountered.
    • to

      public static <T> T to(String input, Type type, Type... args) throws ParseException
      Parses an input into the specified parameterized object type using the DEFAULT marshaller.

      A shortcut for calling DEFAULT.read(input, type, args).

      Type Parameters:
      T - The class type of the object to create.
      Parameters:
      input - The input.
      type - The object type to create.
      args - The type arguments of the class if it's a collection or map.
      Returns:
      The parsed object.
      Throws:
      ParseException - Malformed input encountered.