| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Composite.Aeson.TH
Documentation
makeFieldJsonWrapper :: String -> Name -> SumStyle -> Q [Dec] Source #
TH splice which makes it more convenient to define DefaultJsonFormat, ToJSON, and FromJSON instances for Field types.
For example:
type MyField = '[FFoo, FBar] makeFieldJsonWrapper MyFieldJson ''MyField SumStyleFieldName
is equivalent to:
newtype MyFieldJson = MyFieldJson { unMyFieldJson :: Field MyField }
myFieldJsonFormat :: JsonFormatField Void MyFieldJson
myFieldJsonFormat =
dimapJsonFormat unMyFieldJson MyFieldJson $
fieldJsonFormat SumStyleFieldName defaultJsonFormatField
instance FromJSON MyFieldJson where
parseJSON = parseJsonWithFormat' myFieldJsonFormat
instance ToJSON MyFieldJson where
toJSON = toJsonWithFormat myFieldJsonFormat
This function uses defaultJsonFormatField to derive the formatting for the field. If you want to customize that formatting, use
makeFieldJsonWrapperExplicit instead.
makeFieldJsonWrapperExplicit :: String -> Name -> SumStyle -> Q Exp -> Q [Dec] Source #
TH splice which makes it more convenient to define DefaultJsonFormat, ToJSON, and FromJSON instances for Field types.
For example:
type MyField = '[FFoo, FBar] makeRecJsonWrapperExplicit MyFieldJson ''MyField [| set (rlens fFoo_) specialFormat defaultJsonFormatRecord |]
is equivalent to:
newtype MyFieldJson = MyFieldJson { unMyFieldJson :: Record MyField }
myRecordJsonFormat :: JsonFormatRecord Void MyFieldJson
myRecordJsonFormat =
dimapJsonFormat unMyFieldJson MyFieldJson $
recordJsonFormat (set (rlens fFoo_) specialFormat defaultJsonFormatRecord)
instance FromJSON MyFieldJson where
parseJSON = parseJsonWithFormat' myRecordJsonFormat
instance ToJSON MyFieldJson where
toJSON = toJsonWithFormat myRecordJsonFormat
makeRecordJsonWrapper :: String -> Name -> Q [Dec] Source #
TH splice which makes it more convenient to define DefaultJsonFormat, ToJSON, and FromJSON instances for Record types.
For example:
type MyRecord = '[FFoo, FBar] makeRecJsonWrapper MyRecordJson ''MyRecord
is equivalent to:
newtype MyRecordJson = MyRecordJson { unMyRecordJson :: Record MyRecord }
myRecordJsonFormat :: JsonFormatRecord Void MyRecordJson
myRecordJsonFormat =
dimapJsonFormat unMyRecordJson MyRecordJson $
recordJsonFormat defaultJsonFormatRecord
instance FromJSON MyRecordJson where
parseJSON = parseJsonWithFormat' myRecordJsonFormat
instance ToJSON MyRecordJson where
toJSON = toJsonWithFormat myRecordJsonFormat
This function uses defaultJsonFormatRecord to derive the formatting for the record. If you want to customize that formatting, use
makeRecJsonWrapperExplicit instead.
makeRecordJsonWrapperExplicit :: String -> Name -> Q Exp -> Q [Dec] Source #
TH splice which makes it more convenient to define DefaultJsonFormat, ToJSON, and FromJSON instances for Record types.
For example:
type MyRecord = '[FFoo, FBar] makeRecordJsonWrapperExplicit MyRecordJson ''MyRecord [| set (rlens fFoo_) specialFormat defaultJsonFormatRecord |]
is equivalent to:
newtype MyRecordJson = MyRecordJson { unMyRecordJson :: Record MyRecord }
myRecordJsonFormat :: JsonFormatRecord Void MyRecordJson
myRecordJsonFormat =
dimapJsonFormat unMyRecordJson MyRecordJson $
recordJsonFormat (set (rlens fFoo_) specialFormat defaultJsonFormatRecord)
instance DefaultJsonFormat MyRecordJson where
defaultJsonFormat = myRecordJsonFormat
instance FromJSON MyRecordJson where
parseJSON = parseJsonWithFormat' myRecordJsonFormat
instance ToJSON MyRecordJson where
toJSON = toJsonWithFormat myRecordJsonFormat