Class JsonLdSerializer

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

public class JsonLdSerializer extends RdfSerializer
Subclass of RdfSerializer for serializing POJOs to JSON-LD format.

Produces RDF in W3C JSON-LD syntax, a JSON-based format for linked data. JSON-LD is widely used for web APIs and integrates well with JSON tooling.

Examples:

// Serialize a bean to JSON-LD string. Person person = new Person("Alice", 30); String jsonLd = JsonLdSerializer.DEFAULT.write(person);

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

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

Example output (bean with name/age):

{ "@context": {...}, "@id": "...", "@type": "Person", "name": "Alice", "age": 30 }

Complex (nested address + array):

{ "@context": {...}, "@id": "...", "@type": "Person", "name": "Alice", "age": 30, "address": { "@id": ".../address", "street": "123 Main St", "city": "Boston", "state": "MA" }, "tags": ["a","b","c"] }

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