I am currently learning about RDF and I am attempting to convert an RDF document into a Java Bean.
So far I have found and used the Jena
library to read in an RDF Turtle document. I can then iterate over the statements within the Jena model and print out each statements subject, predicate and object. But instead I would like to convert/bind the RDF within the model to a Java bean.
Here is the code I am using to read the RDF Turtle into the Jena bean:
Model model = new ModelCom(new GraphMem());
model.read(new ByteArrayInputStream(body.getBytes()), null, "TURTLE");
Property predicate;
Statement statement;
Resource subject;
RDFNode obj;
StmtIterator iter = model.listStatements();
while(iter.hasNext()) {
statement = iter.next();
subject = statement.getSubject();
System.out.println("Subject = " + subject.getURI());
predicate = statement.getPredicate();
System.out.println("Predicate = " +predicate.getLocalName());
obj = statement.getObject();
System.out.println("Object = " + obj.toString());
}
I have tried for a couple of days, but I cannot find any documentation anywhere that demonstrates how to bind a model to a Java bean.
Ideally what I would like to do is:
Person person = model.read(Person.class);