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
KeyValbeing 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:
Charsare 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,
DateTimesare translated into a BSON ISODate. - In Cassandra, when
DateTimesare stored in individual columns, they are stored as timestamps
- Empty
Optionsare omitted from the JSON. - Non-empty
Optionsare inlined, so thatSome(expr)will produce the same JSON asexpr. SetsandListsare translated into JSON arrays.