api-tools-0.9.0.0: DSL for generating API boilerplate and docs
Safe HaskellNone
LanguageHaskell2010

Data.API.JSONToCBOR

Synopsis

Documentation

serialiseJSONWithSchema :: API -> TypeName -> Value -> ByteString Source #

Serialise a JSON value as a CBOR term in a generic but schema-dependent fashion. This is necessary because the JSON representation carries less information than we need in CBOR (e.g. it lacks a distinction between bytestrings and text).

jsonToCBORWithSchema :: API -> TypeName -> Value -> Term Source #

Convert a JSON value into a CBOR term in a generic but schema-dependent fashion.

deserialiseJSONWithSchema :: API -> TypeName -> ByteString -> Value Source #

When a JSON value has been deserialised from CBOR, the representation may need some modifications in order to match the result of toJSON on a Haskell datatype. In particular, Aeson's representation of Maybe does not round-trip (because Nothing is encoded as Null and Just x as toJSON x), so CBOR uses a different representation (as an empty or 1-element list).