JB4JSON-LD is a library for convenient serialization and deserialization of POJOs into/from JSON-LD. Its main goal is to simplify publishing semantic content through REST services.
JB4JSON-LD uses annotations from JOPA for mapping classes and their attributes to JSON-LD objects and their properties.
Downloads and Links
The source codes are hosted on Github. The project itself consists of two parts:
- Core implementation, which handles the serialization/deserialization, available at https://github.com/kbss-cvut/jb4jsonld.
- Library bindings, which connect the core to JSON implementations like Jackson or MOXy. Currently, only Jackson integration exists - available at https://github.com/kbss-cvut/jb4jsonld-jackson.
The library is built using Maven and available in Maven central.
Use the following dependency in your pom to get the Jackson binding of JB4JSON-LD:
Or use the following one to get the core implementation (not very useful unless you want to develop bindings for other libraries):
Create a JOPA entity using the OWLClass, OWLObjectProperty, OWLDataProperty and OWLAnnotationProperty annotations.
An instance of the following entity:
would be serialized into the following JSON-LD:
"http://purl.org/dc/terms/created":"Wed Aug 24 09:47:11 CEST 2016",
Data properties are serialized as attribute values, object properties are serialized as embedded objects. If an instance is referenced in multiple places, only the first occurrence is written as a full JSON object, other occurrences are serialized as IRIs of the instance.
As can be seen, the output is basically a compacted JSON-LD, but without the context - all properties use full IRIs. Context support is planned for future releases.
Deserialization can handle most kinds of JSON-LD formats, because we are using jsonld-java to process the input before parsing it. Therefore, compacted, flattened, framed or expanded forms of JSON-LD can be all handled by the deserializer.
Again, multiple references to the same entity in the JSON should be realized by using the entity's IRI in all but the first occurrence.