@@ -249,7 +249,7 @@ modifyFailure f (Parser p) = Parser $ \kf -> p (kf . f)
249249-- Generic and TH encoding configuration
250250--------------------------------------------------------------------------------
251251
252−-- | Options that specify how to encode/decode your datatype to/from JSON.
252+-- | Options that specify how to encode\/decode your datatype to\/from JSON.
253253data Options = Options
254254 { fieldNameModifier :: String -> String
255255 -- ^ Function applied to field names.
@@ -257,39 +257,43 @@ data Options = Options
257257 , constructorNameModifier :: String -> String
258258 -- ^ Function applied to constructor names.
259259 -- Handy for lower-casing constructor names for example.
260− , nullaryToString :: Bool
261− -- ^ If 'True' the constructors of a datatype, with all nullary
260+ , nullaryToString :: Bool
261+ -- ^ If 'True' the constructors of a datatype, with /all/ nullary
262262 -- constructors, will be encoded to a string with the
263263 -- constructor name. If 'False' the encoding will always follow
264264 -- the `sumEncoding`.
265265 , omitNothingFields :: Bool
266266 -- ^ If 'True' record fields with a 'Nothing' value will be
267267 -- omitted from the resulting object. If 'False' the resulting
268− -- object will include those fields with @null@ values.
269− , sumEncoding :: SumEncoding
268+ -- object will include those fields mapping to @null@.
269+ , sumEncoding :: SumEncoding
270270 -- ^ Specifies how to encode constructors of a sum datatype.
271271 }
272272
273273-- | Specifies how to encode constructors of a sum datatype.
274274data SumEncoding =
275− TwoElemArray -- ^ A constructor will be encoded to a 2-element
276− -- array where the first element is the name of the
277− -- constructor (modified by the
278− -- 'constructorNameModifier') and the second element
279− -- the content of the constructor.
280− | ObjectWithType { typeFieldName :: String
275+ ObjectWithType { typeFieldName :: String
281276 , valueFieldName :: String
282277 }
283278 -- ^ A constructor will be encoded to an object with a field
284279 -- 'typeFieldName' which specifies the constructor name (modified
285− -- by the 'constructorNameModifier'). If the constructor is not a
286− -- record the constructor content will be stored under the
280+ -- by the 'constructorNameModifier'). If the constructor is a
281+ -- record the encoded record fields will be unpacked into this
282+ -- object. So make sure that your record doesn't have a field with
283+ -- the same name as the 'typeFieldName'. Otherwise the type gets
284+ -- overwritten by that field. If the constructor is not a record
285+ -- the encoded constructor content will be stored under the
287286 -- 'valueFieldName' field.
288287 | ObjectWithSingleField
289288 -- ^ A constructor will be encoded to an object with a single
290289 -- field named after the constructor (modified by the
291− -- 'constructorNameModifier') and the value will be the contents
290+ -- 'constructorNameModifier') which maps to the encoded contents
292291 -- of the constructor.
292+ | TwoElemArray
293+ -- ^ A constructor will be encoded to a 2-element array where the
294+ -- first element is the name of the constructor (modified by the
295+ -- 'constructorNameModifier') and the second element the encoded
296+ -- content of the constructor.
293297
294298-- | Default encoding 'Options':
295299--