Class TurtleSerializer

All Implemented Interfaces:
Function<Object,String>, ThrowingFunction<Object,String>, RdfMetaProvider, XmlMetaProvider

public class TurtleSerializer extends RdfSerializer
Subclass of RdfSerializer for serializing POJOs to Turtle format.

Produces compact, human-readable RDF in W3C Turtle syntax. Turtle is widely used for RDF interchange and is often more readable than RDF/XML.

Examples:

// Serialize a bean to Turtle string. Person person = new Person("Alice", 30); String turtle = TurtleSerializer.DEFAULT.write(person);

// Or use the Turtle marshaller for convenience. String turtle = Turtle.DEFAULT.write(person);

// Custom serializer with swaps. TurtleSerializer s = TurtleSerializer.create().swaps(DateSwap.class).build(); String turtle = s.write(bean);

Example output (bean with name/age):

@prefix j: <...> . <...> a j:Person ; j:name "Alice" ; j:age 30 .

Complex (nested address + array):

@prefix j: <...> . <...> a j:Person ; j:name "Alice" ; j:age 30 ; j:address <.../address> ; j:tags <.../tags> . <.../address> a j:Address ; j:street "123 Main St" ; j:city "Boston" ; j:state "MA" . <.../tags> j:member "a", "b", "c" .

Notes:

  • This class is thread safe and reusable.

See Also: