@@ -249,7 +249,7 @@ modifyFailure f (Parser p) = Parser $ \kf -> p (kf . f)
249-- Generic and TH encoding configuration
249-- Generic and TH encoding configuration
250--------------------------------------------------------------------------------
250--------------------------------------------------------------------------------
252−-- | Options that specify how to encode your datatype to JSON.
252+-- | Options that specify how to encode/decode your datatype to/from JSON.
253data Options = Options
253data Options = Options
254 { fieldNameModifier :: String -> String
254 { fieldNameModifier :: String -> String
255 -- ^ Function applied to field names.
255 -- ^ Function applied to field names.
@@ -258,10 +258,14 @@ data Options = Options
258 -- ^ Function applied to constructor names.
258 -- ^ Function applied to constructor names.
259 -- Handy for lower-casing constructor names for example.
259 -- Handy for lower-casing constructor names for example.
260 , nullaryToString :: Bool
260 , nullaryToString :: Bool
261− -- ^ If 'True' the constructors of a datatypes, with all nullary
261+ -- ^ If 'True' the constructors of a datatype, with all nullary
262 -- constructors, will be encoded to a string with the
262 -- constructors, will be encoded to a string with the
263 -- constructor name. If 'False' the encoding will always follow
263 -- constructor name. If 'False' the encoding will always follow
264 -- the `sumEncoding`.
264 -- the `sumEncoding`.
265+ , omitNothingFields :: Bool
266+ -- ^ If 'True' record fields with a 'Nothing' value will be
267+ -- omitted from the resulting object. If 'False' the resulting
268+ -- object will include those fields with @null@ values.
265 , sumEncoding :: SumEncoding
269 , sumEncoding :: SumEncoding
266 -- ^ Specifies how to encode constructors of a sum datatype.
270 -- ^ Specifies how to encode constructors of a sum datatype.
@@ -287,19 +291,27 @@ data SumEncoding =
287 -- 'constructorNameModifier') and the value will be the contents
291 -- 'constructorNameModifier') and the value will be the contents
288 -- of the constructor.
292 -- of the constructor.
290−-- | Default encoding options which specify to not modify field and
294+-- | Default encoding 'Options':
291−-- constructor names, encode the constructors of a datatype with all
295+--
292−-- nullary constructors to just strings with the name of the
296+-- @
293−-- constructor and use a 2-element array for other sum datatypes.
297+-- 'Options'
298+-- { 'fieldNameModifier' = id
299+-- , 'constructorNameModifier' = id
300+-- , 'nullaryToString' = True
301+-- , 'omitNothingFields' = True
302+-- , 'sumEncoding' = 'TwoElemArray'
294defaultOptions :: Options
305defaultOptions :: Options
295defaultOptions = Options
306defaultOptions = Options
296 { fieldNameModifier = id
307 { fieldNameModifier = id
297 , constructorNameModifier = id
308 , constructorNameModifier = id
298 , nullaryToString = True
309 , nullaryToString = True
310+ , omitNothingFields = True
299 , sumEncoding = TwoElemArray
311 , sumEncoding = TwoElemArray
302−-- | Note that:
314+-- | Default 'ObjectWithType' 'SumEncoding' options:
305-- defaultObjectWithType = 'ObjectWithType'
317-- defaultObjectWithType = 'ObjectWithType'