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

Safe HaskellNone
LanguageHaskell2010

Composite.Aeson.TH

Synopsis

Documentation

makeRecJsonWrapper :: String -> Name -> Q [Dec] Source #

TH splice which makes it more convenient to define ToJSON / FromJSON instances for record types.

For example:

  type MyRecord = '[FFoo, FBar]
  makeRecJsonWrapper MyRecordJson ''MyRecord

is equivalent to:

  newtype MyRecordJson = MyRecordJson { unMyRecordJson :: Record MyRecord }
  myRecordJsonFormat :: JsonFormatRec Void MyRecordJson
  myRecordJsonFormat =
    dimapJsonFormat unMyRecordJson MyRecordJson $
      recJsonFormat defaultJsonFormatRec
  instance FromJSON MyRecordJson where
    parseJSON = parseJsonWithFormat' myRecordJsonFormat
  instance ToJSON MyRecordJson where
    toJSON = toJsonWithFormat myRecordJsonFormat

This function uses defaultJsonFormatRec to derive the formatting for the record. If you want to customize that formatting, use makeRecJsonWrapperExplicit instead.

makeRecJsonWrapperExplicit :: String -> Name -> Q Exp -> Q [Dec] Source #

TH splice which makes it more convenient to define ToJSON / FromJSON instances for record types.

For example:

  type MyRecord = '[FFoo, FBar]
  makeRecJsonWrapperExplicit MyRecordJson ''MyRecord [| set (rlens fFoo_) specialFormat defaultJsonFormatRec |]

is equivalent to:

  newtype MyRecordJson = MyRecordJson { unMyRecordJson :: Record MyRecord }
  myRecordJsonFormat :: JsonFormatRec Void MyRecordJson
  myRecordJsonFormat =
    dimapJsonFormat unMyRecordJson MyRecordJson $
      recJsonFormat (set (rlens fFoo_) specialFormat defaultJsonFormatRec)
  instance FromJSON MyRecordJson where
    parseJSON = parseJsonWithFormat' myRecordJsonFormat
  instance ToJSON MyRecordJson where
    toJSON = toJsonWithFormat myRecordJsonFormat