Safe Haskell | None |
---|
Documentation
:: (String -> String) | Function to change field names. |
-> Name | Name of the type for which to generate |
-> Q [Dec] |
Generates both ToJSON
and FromJSON
instance declarations for the given
data type.
This is a convienience function which is equivalent to calling both
deriveToJSON
and deriveFromJSON
.
:: (String -> String) | Function to change field names. |
-> Name | Name of the type for which to generate a |
-> Q [Dec] |
Generates a ToJSON
instance declaration for the given data type.
Example:
data Foo = FooChar
Int
$(deriveToJSON
id
''Foo)
This will splice in the following code:
instanceToJSON
Foo wheretoJSON
= value -> case value of Foo arg1 arg2 ->Array
$create
$ do mv <-unsafeNew
2unsafeWrite
mv 0 (toJSON
arg1)unsafeWrite
mv 1 (toJSON
arg2) return mv
:: (String -> String) | Function to change field names. |
-> Name | Name of the type for which to generate a |
-> Q [Dec] |
Generates a FromJSON
instance declaration for the given data type.
Example:
data Foo = Foo Char Int
$(deriveFromJSON
id ''Foo)
This will splice in the following code:
instanceFromJSON
Foo whereparseJSON
= value -> case value ofArray
arr -> if (V.length arr == 2) then Foo <$>parseJSON
(arrunsafeIndex
0) <*>parseJSON
(arrunsafeIndex
1) else fail "<error message>" other -> fail "<error message>"
Generates a lambda expression which parses the JSON encoding of the given data type.
Example:
data Foo = Foo Int
parseFoo ::Value
->Parser
Foo parseFoo = $(mkParseJSON
id ''Foo)
This will splice in the following code:
\value -> case value of arg -> Foo <$> parseJSON
arg