composite-aeson-0.6.2.0: JSON for Vinyl/Frames records

Safe HaskellNone
LanguageHaskell2010

Composite.Aeson.Enum

Synopsis

Documentation

enumJsonFormat :: forall e a. (Show a, Ord a, Generic a, ConNames (Rep a), Enum' (Rep a)) => String -> JsonFormat e a Source #

For some type a which represents an enumeration (i.e. all nullary constructors) generate a JsonFormat which maps that type to strings in JSON.

Each constructor will be mapped to a string with the same value as its name with some prefix removed.

For example, given:

data MyEnum = MyEnumFoo | MyEnumBar
myEnumFormat :: JsonFormat e MyEnum
myEnumFormat = enumJsonFormat "MyEnum"

Then:

toJsonWithFormat myEnumFormat MyEnumFoo == Aeson.String "Foo"

enumMapJsonFormat :: Show a => (Text -> Maybe a) -> (a -> Maybe Text) -> String -> JsonFormat e a Source #

For some type a which bidirectional mapping functions can be provided, produce a JsonFormat which maps to JSON strings.