public class RdfJson extends CharMarshaller
A pairing of a RdfJsonSerializer and RdfJsonParser into a single class with convenience to/of methods.
Examples:

// Serialize a bean or map to RDF/JSON String rdfJson = RdfJson.of(myBean); // Parse RDF/JSON into a bean or map MyPojo parsed = RdfJson.to(rdfJson, MyPojo.class);

// Using instance methods RdfJson m = RdfJson.DEFAULT; rdfJson = m.write(myBean); parsed = m.read(rdfJson, MyPojo.class);

Example output (bean with name/age, RDF/JSON format):

{ "<subject>": { "<.../name>": [{ "value": "Alice" }], "<.../age>": [{ "value": 30, "type": "literal" }] } }

Complex (nested address + array):

{ "<...>": { "<.../name>": [{ "value": "Alice" }], "<.../address>": [{ "type": "uri", "value": ".../address" }] }, "<.../address>": { "<.../street>": [{ "value": "123 Main St" }], "<.../city>": [{ "value": "Boston" }], "<.../state>": [{ "value": "MA" }] } }

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

See Also:
  • Field Details

    • DEFAULT

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

    • RdfJson

      public RdfJson()
      Constructor using defaults.
    • RdfJson

      Constructor with serializer and parser.
      Parameters:
      s - The serializer to use.
      Must not be null.
      p - The parser to use.
      Must not be null.
  • 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.