JB4JSON-LD

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:

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:

<dependency>
    <groupId>cz.cvut.kbss.jsonld</groupId>
    <artifactId>jb4jsonld-jackson</artifactId>
</dependency>

Or use the following one to get the core implementation (not very useful unless you want to develop bindings for other libraries):

<dependency>
    <groupId>cz.cvut.kbss.jsonld</groupId>
    <artifactId>jb4jsonld</artifactId>
</dependency>


Usage

Create a JOPA entity using the OWLClass, OWLObjectProperty, OWLDataProperty and OWLAnnotationProperty annotations.

Serialization

An instance of the following entity:

would be serialized into the following JSON-LD:


   "@type":[ 
      "http://krizik.felk.cvut.cz/ontologies/jb4jsonld/Employee"
   ],
   "http://xmlns.com/foaf/0.1/firstName":"FirstName1292426484",
   "http://xmlns.com/foaf/0.1/lastName":"LastName1292426484",
   "@id":"http://krizik.felk.cvut.cz/ontologies/jaxb-jsonld#-349122419",
   "http://xmlns.com/foaf/0.1/accountName":"user1292426484",
   "http://krizik.felk.cvut.cz/ontologies/
jb4jsonld/isMemberOf":{ 
      "@type":[ 
         "http://krizik.felk.cvut.cz/ontologies/
jb4jsonld/Organization"
      ],
      "http://purl.org/dc/terms/created":"Wed Aug 24 09:47:11 CEST 2016",
      "http://krizik.felk.cvut.cz/ontologies/
jb4jsonld/brand":[ 
         "Brandy0",
         "Brandy1"
      ],
      "http://www.w3.org/2000/01/rdf-schema#label":"Organization-463016788",
      "@id":"http://krizik.felk.cvut.cz/ontologies/j
jb4jsonld#122628143"
   },
   "http://krizik.felk.cvut.cz/ontologies/j
jb4jsonld/isAdmin":false
}

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

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.