longevity

A Persistence Framework for Scala and NoSQL

View project on GitHub

persistent to json

As of now, all longevity database back ends translate persistent objects in and out of some JSON variant. MongoDB uses BSON, whereas in Cassandra, the persistent object is stored in JSON form in one of the columns. The translation itself is quite straightforward:

  • Persistent objects, persistent components, and key values are translated into JSON Objects.
  • If a persistent component or a KeyVal being translated only has a single member, that member value is inlined, so that the JSON produced is whatever JSON the member value produces.
  • Basic values translate directly into JSON primitive types, with two exceptions:
    • Chars are translated into single-character strings.
    • DateTimes are converted to UTC time zone before serializing to avoid ordering issues.
      • In (non-BSON) JSON, they are converted into a string in a lossless ISO 8061 format.
      • In Mongo, DateTimes are translated into a BSON ISODate.
      • In Cassandra, when DateTimes are stored in individual columns, they are stored as timestamps
  • Empty Options are omitted from the JSON.
  • Non-empty Options are inlined, so that Some(expr) will produce the same JSON as expr.
  • Sets and Lists are translated into JSON arrays.
prev: translating persistents to the database
up: translating persistents to the database
next: cassandra translation