registry-aeson-0.2.2.0: Aeson encoders / decoders
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Registry.Aeson.TH.Decoder

Synopsis

Documentation

makeDecoder :: Name -> ExpQ Source #

Make a Decoder for a given data type Usage: $(makeDecoder ''MyDataType <: otherDecoders)

makeConstructorsDecoder :: Name -> [Con] -> ExpQ Source #

Make a decoder for a given data type by extracting just enough metadata about the data type in order to be able to parse a Value

For example for the data type:

data T = T1 {f1::Int, f2::Int} | T2 Int Int

we add this function to the registry:

opts d1 d2 d3 -> Decoder $ v -> decodeFromDefinitions opts v $ case ToConstructor T1 [v1, v2]-> T1 $ d1 v1 * d2 v2 ... ToConstructor T2 [v1, v2]-> T2 $ d1 v1 * d3 v2 ... other -> Left ("cannot decode " <> valueToText v)

The case function is the only one which needs to be generated in order to match the exact shape of the constructors to instantiate

makeMatchClause :: Name -> [Type] -> Con -> MatchQ Source #

Decode the nth constructor of a data type ToConstructor T1 [v1, v2]-> T1 $ d1 v1 * d2 v2 ...

makeErrorClause :: Name -> MatchQ Source #

Return an error the json value cannot be decoded with a constructor name and some values