Data Types

PA4RDF will convert to/from any registered typed literal including the standard Java primitives and wrapped primitive types.

If the return type or parameter of an @Predicate annotated is another @Subject annotated class PA4RDF will automatically create and map the class as appropriate.

Data Type Mapping

To perform the conversion the following steps are taken:

The RDFDatatype associated with the return type is looked up using the TypeMapper. If found the return type value is created using the the RDFDatatype.

Otherwise: if the return type class is annotated with @Subject the class is automatically created by the entity manager.

Otherwise: if the return type is an instance of RDFNode the graph node is returned.

Otherwise: if the return type is the URI class the URI of the graph node is returned.

Otherwise: null is returned.

Default Java Type to Data Type Mapping

Java Type RDF Type

Thus is a @Property annotated setter method takes a Float argument the data type as stored in the graph will be

Default Data Type to Java Mapping

RDF Type Java Type byte[] java.lang.Boolean java.lang.Byte com.hp.hpl.jena.datatypes.xsd.XSDDateTime java.math.BigDecimal java.lang.Double com.hp.hpl.jena.datatypes.xsd.XSDDuration java.lang.Float java.lang.Integer java.math.BigInteger java.lang.Long java.lang.String java.lang.Short char

Primitive Data Types

Primitive data types are automatically converted to their non-primitive form as necessary. One caveat: if the return type of a @Property annotated method is a primitive and the data element does not exist in the graph a NullPointerException is thrown.

Adding Additional Data Types

Additional data types may be registered using the standard Jena process:

1 Create a class that extends com.hp.hpl.jena.datatypes.RDFDatatype. 2 Register the class with the com.hp.hpl.jena.datatypes.TypeMapper.

com.hp.hpl.jena.datatypes. rtype = new MyDatatype();

Displaying Registered Data Types

Registered data types may be displayed using org.xenei.jena.entities.DumpDataTypes


  1. Output format. The format is a String.format format string for two (2) string inputs. The default is %s | %s. To reverse the display use %2$s | %1$s.
  • The first format parameter is the URI of the data type,
  • The second format parameter is the class name.
  1. null class string. This is the string to print if the java class is not defined.If the nullCLassString is null registered data types without classes will not be printed.