| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Servant.EDE.Internal.ToObject
Documentation
Turn haskell values into JSON objects.
This is the mechanism used by EDE to marshall data from Haskell
to the templates. The rendering is then just about feeding the
resulting Object to a compiled Template. Example:
import Text.EDE
data User = User { name :: String, age :: Int }
instance ToObject User where
toObject user =
fromPairs [ "name" .= name user
, "age" .= age user
]However, you're not forced to write the instance yourself for such a type.
Indeed, for any record type (i.e a datatype with a single constructor and
with field selectors) you can let GHC.Generics derive the ToObject instance
for you.
data User = User { name :: String, age :: Int } deriving Generic
instance ToObject UserThis will generate an equivalent instance to the previous one.
Minimal complete definition
Nothing
Methods