RDF Details
Juneau supports serializing and parsing arbitrary POJOs to and from the following RDF formats:
- RDF/XML
- Abbreviated RDF/XML
- N-Triple
- Turtle
- N3
The serializers and parsers work identically to those in juneau-marshall, but are
packaged separately so that you don't need to pull in the Jena dependency unless you need it.
// A simple bean
public class Person {
public String name = "John Smith";
public int age = 21;
}
// Serialize a bean to JSON, XML, or HTML
Person person = new Person();
// Produces:
// <rdf:RDF
// xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
// xmlns:jp="http://www.apache.org/juneaubp/"
// xmlns:j="http://www.apache.org/juneau/">
// <rdf:Description>
// <jp:name>John Smith</jp:name>
// <jp:age>21</jp:age>
// </rdf:Description>
// </rdf:RDF>
String rdfXml = RdfSerializer.DEFAULT_XMLABBREV.serialize(person);
// Produces:
// @prefix jp: <http://www.apache.org/juneaubp/> .
// @prefix j: <http://www.apache.org/juneau/> .
// [] jp:age "21" ;
// jp:name "John Smith" .
String rdfN3 = N3Serializer.DEFAULT.serialize(person);
// Produces:
// _:A3bf53c85X3aX157cf407e2dX3aXX2dX7ffd <http://www.apache.org/juneaubp/name> "John Smith" .
// _:A3bf53c85X3aX157cf407e2dX3aXX2dX7ffd <http://www.apache.org/juneaubp/age> "21" .
String rdfNTriple = RdfSerializer.DEFAULT_NTRIPLE.serialize(person);