JSON Datastores

DataNucleus supports persisting/retrieving objects to/from JSON documents (using the datanucleus-json plugin). Simply specify your "connectionURL" as follows


replacing "{url}" with some URL of your choice (e.g "http://www.mydomain.com/somepath/"). You then create your PMF/EMF as normal and use JDO/JPA as normal.

Things to bear in mind with JSON usage :-

  • Querying can be performed using JDOQL or JPQL. Any filtering/ordering will be performed in-memory
  • Relations : A spreadsheet cannot store related objects directly, since each object is a row of a particular worksheet. DataNucleus gets around this by storing the String-form of the identity of the related object in the relation cell.

Mapping : HTTP Mapping

The persistence to JSON datastore is performed via HTTP methods. HTTP response codes are used to validate the success or failure to perform the operations. The JSON datastore must respect the following:

Method Operation URL format HTTP response code
PUT update objects /{primary key} HTTP Code 201 (created), 200 (ok) or 204 (no content)
HEAD locate objects /{primary key} HTTP 404 if the object does not exist
POST insert objects / HTTP Code 201 (created), 200 (ok) or 204 (no content)
GET fetch objects /{primary key} HTTP Code 200 (ok) or 404 if object does not exist
GET retrieve extent of classes (set of objects) / HTTP Code 200 (ok) or 404 if no objects exist
DELETE delete objects /{primary key} HTTP Code 202 (accepted), 200 (ok) or 204 (no content)

Mapping : Persistent Classes
Metadata API Extension Element Attachment Extension Description
JDO /jdo/package/class/extension url Defines the location of the resources/objects for the class
    <package name="org.datanucleus.samples.models.company">
        <class name="Person" detachable="true">
            <extension vendor-name="datanucleus" key="url" value="/Person"/>

In this example, the url extension identifies the Person resources/objects as /Person . The persistence operations will be relative to this path. e.g /Person/{primary key} will be used for PUT (update), GET (fetch) and DELETE (delete) methods.