Skip to content

Latest commit

 

History

History
88 lines (64 loc) · 2.75 KB

README.md

File metadata and controls

88 lines (64 loc) · 2.75 KB

Java Binding for JSON-LD

Java Binding for JSON-LD (JB4JSON-LD) is a simple library for serialization of Java objects into JSON-LD and vice versa.

Note that this is the core, abstract implementation. For actual usage, a binding like https://github.com/kbss-cvut/jb4jsonld-jackson has to be used.

More information can be found at https://kbss.felk.cvut.cz/web/portal/jb4jsonld.

Usage

JB4JSON-LD is based on annotations from JOPA, which enable POJO attributes to be mapped to ontological constructs (i.e. to object, data or annotation properties) and Java classes to ontological classes.

Use @OWLDataProperty to annotate data fields and @OWLObjectProperty to annotate fields referencing other mapped entities.

See https://github.com/kbss-cvut/jopa-examples/tree/master/jsonld for an executable example of JB4JSON-LD in action (together with Spring and Jackson).

Example

Java

@OWLClass(iri = "http://onto.fel.cvut.cz/ontologies/ufo/Person")
public class User {

    @Id
    public URI uri;

    @OWLDataProperty(iri = "http://xmlns.com/foaf/0.1/firstName")
    private String firstName;

    @OWLDataProperty(iri = "http://xmlns.com/foaf/0.1/lastName")
    private String lastName;
    
    @OWLDataProperty(iri = "http://xmlns.com/foaf/0.1/accountName")
    private String username;

    @Properties
    private Map<String, Set<String>> properties;
    
    // Getters and setters follow
}

JSON-LD

{
  "@context": {
    "firstName": "http://xmlns.com/foaf/0.1/firstName",
    "lastName": "http://xmlns.com/foaf/0.1/lastName",
    "accountName": "http://xmlns.com/foaf/0.1/accountName",
    "isAdmin": "http://krizik.felk.cvut.cz/ontologies/jb4jsonld/isAdmin"
  },
  "@id": "http://krizik.felk.cvut.cz/ontologies/jb4jsonld#Catherine+Halsey",
  "@type": [
    "http://onto.fel.cvut.cz/ontologies/ufo/Person",
    "http://krizik.felk.cvut.cz/ontologies/jb4jsonld/User",
    "http://onto.fel.cvut.cz/ontologies/ufo/Agent"
  ],
  "isAdmin": true,
  "accountName": "halsey@unsc.org",
  "firstName": "Catherine",
  "lastName": "Halsey"
}

Getting JB4JSON-LD

There are two ways to get JB4JSON-LD:

  • Clone repository/download zip and build it with Maven,
  • Use a Maven dependency:
<dependency>
    <groupId>cz.cvut.kbss.jsonld</groupId>
    <artifactId>jb4jsonld</artifactId>
    <version>0.1.0</version>
</dependency>

Note that you will most likely need an integration with a JSON-serialization library like JB4JSON-LD-Jackson.