CodecsThere are two critical aspects to codecs, encode a data type to json, and decode a data type from json. Encoding is handled by the
EncodeJsontype class. Decoding is handled by the
DecodeJsontype class. Both can be defined at once using the
Defining an encode json instance is straight forward, you just need to provide a function that takes your type and produces a json object.
We also provide a set of very convenient methods for building EncodeJson instances.
Defining a decode json instance is more involved, as you have to handle the chance of failure where you may not be able to decode your type.
DecodeJson works on a HCursor. This
allows codecs to be combined whilst mainting efficiency and
tracking cursor movements for nice error messages.
DecodeJson directly you need to build your data
type from a cursor and return a
We also provide a set of very convenient methods for building DecodeJson instances.
CodecJson allows you to construct both an encode and decode at the same time.
CodecJson you pass two arguments, the first is as per
the second is as per
We also provide a set of very convenient methods for building CodecJson instances.