Fork me on GitHub


What is Hippo JCR POJO Binding?

This project aims to provide a simple set of POJO beans with which you can map JCR (document, binary, etc) nodes to POJO (ContentNode) beans, and also bind the POJO beans back to JCR (document, binary, etc) nodes. The POJO beans provided by this project are very friendly to most marshalling/unmarshalling frameworks such as Jackson (for JSON), JAXB (for XML) or any others (for YAML as an example). Therefore, you can easily export JCR content through the POJO (ContentNode) beans after mapping, and import data through the (unmarshalled) POJO (ContentNode) beans to JCR content by binding.

Hippo JCR POJO Binding

As depicted in the diagram above, what this project provides is in the light yellow area in the center. The left and right area are out of scope in this project.

Some pointers are:

  • JCR nodes can be easily mapped to ContentNode POJO beans provided by this project.
  • ContentNode POJO beans can be used to update JCR nodes back in binding process.
  • Because ContentNode is purely lightweight POJO bean without any stateful members such as javax.jcr.Node or javax.jcr.Property, you can easily marshal the ContentNode POJO beans to JSON or XML files, and unmarshal the ContentNode POJO beans back from the JSON or XML files.
  • Nowadays, it is very easy to (un)marshal from/to JSON using libraries such as Jackson, and it is also easy to (un)marshal from/to XML using libraries such as JAXB API.
  • Therefore, this project can be valuable especially in case that JCR content should be serialized to files and/or reconstructed or updated JCR content back from the files.

ContentNode and ContentProperty

Basically two main POJO beans are provided by this project: ContentNode and ContentProperty.

ContentNode is analogous to javax.jcr.Node and ContentProperty is analogous to javax.jcr.Property. ContentNode may have multiple ContentProperty items and multiple child ContentNode items like JCR. But they are purely serializable as POJOs. Also, for simplicity, ContentProperty stores all the values in string. It provides type transforming getter methods for convenience though. For example, ContentProperty#getValue(String name) returns a string value, and ContentProperty#getValues(String name) returns a list of string values. However, CotnentProperty#getValueAsObject(String name) returns a transformed object value (e.g, Long, Double, BigDecimal, Calendar, BinaryValue, etc) from the internal string value, and CotnentProperty#getValuesAsObject(String name) returns a list of transformed object values for convenience.

Please see more detail in JavaDocs.

Binary Data Value Handling

It is very crucial to handle binary data properly even in a simple mapping/binding library because the data size of a binary value can be big which may make a bad impact on system availability (e.g, OutOfMemoryError).

So, this library handles binary data values carefully with using BinaryValue unlike other values (other values are always stringified internally for simplicity).

For example, DefaultJcrContentValueConverter (the default ContentValueConverter implementation) is able to automatically serialize a binary data into an external VFS file and keep the URL string only in the ContentProperty instance if the data size exceeds the configured threshold size. If the data size is less than the configured threshold size, it simply converts the binary data into a data: URL (containing a mimeType optionally as well as BASE64 encoded string).

Project status

Please see Release Notes.