Class NQuadsSerializer

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

public class NQuadsSerializer extends RdfSerializer
Subclass of RdfSerializer for serializing POJOs to N-Quads format.

Produces RDF quads (subject, predicate, object, graph) in N-Quads notation. Like N-Triples but with an optional fourth element for the named graph. Useful for RDF datasets.

Examples:

// Serialize a bean to N-Quads string. Person person = new Person("Alice", 30); String nQuads = NQuadsSerializer.DEFAULT.write(person);

// Or use the NQuads marshaller for convenience. String nQuads = NQuads.of(person);

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

Example output (bean with name/age):

<...> <.../name> "Alice" <...> . <...> <.../age> "30"^^<http://www.w3.org/2001/XMLSchema#int> <...> .

Complex (nested address + array):

<...> <.../name> "Alice" <graph> . <...> <.../address> <.../address> <graph> . <.../address> <.../street> "123 Main St" <graph> . <.../address> <.../city> "Boston" <graph> . <.../address> <.../state> "MA" <graph> .

Notes:
  • This class is thread safe and reusable.
See Also: