{title:'Root Property', updated:'9.0.0'}

For all RDF languages, the POJO objects get broken down into simple triplets. Unfortunately, for tree-structured data like the POJOs shown above, this causes the root node of the tree to become lost. There is no easy way to identify that person/1 is the root node in our tree once in triplet form, and in some cases it's impossible.

By default, the {@link oaj.jena.RdfParser} class handles this by scanning all the nodes and identifying the nodes without incoming references. However, this is inefficient, especially for large models. And in cases where the root node is referenced by another node in the model by URL, it's not possible to locate the root at all.

To resolve this issue, the property {@del oaj.jena.RdfSerializer#RDF_addRootProperty} was introduced. When enabled, this adds a special root attribute to the root node to make it easy to locate by the parser.

To enable, set the RDF_addRootProperty property to true on the serializer:

| // Create a new serializer. | RdfSerializer serializer = RdfSerializer.create() | .xmlabbrev() | .rdfxml_tab(3), | .addRootProperty() | .build();

Now when we rerun the sample code, we'll see the added root attribute on the root resource.

| <rdf:RDF | xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | xmlns:j="http://www.apache.org/juneau/" | xmlns:jp="http://www.apache.org/juneaubp/" | xmlns:per="http://www.apache.org/person/" | xmlns:mail="http://www.apache.org/mail/" | xmlns:addr="http://www.apache.org/address/"> | <rdf:Description rdf:about="http://sample/addressBook/person/1"> | <j:root>true</j:root> | <per:addressBookUri rdf:resource="http://sample/addressBook"/> | <per:id>1</per:id> | <per:name>John Smith</per:name> | <per:addresses> | <rdf:Seq> | <rdf:li> | <rdf:Description rdf:about="http://sample/addressBook/address/1"> | <addr:personUri rdf:resource="http://sample/addressBook/person/1"/> | <addr:id>1</addr:id> | <mail:street>100 Main Street</mail:street> | <mail:city>Anywhereville</mail:city> | <mail:state>NY</mail:state> | <mail:zip>12345</mail:zip> | <addr:isCurrent>true</addr:isCurrent> | </rdf:Description> | </rdf:li> | </rdf:Seq> | </per:addresses> | </rdf:Description> | </rdf:RDF>