@@ -581,53 +581,41 @@ data Options = Options
581581 -- the constructor tag. If 'False' the encoding will always
582582 -- follow the `sumEncoding`.
583583 , omitNothingFields :: Bool
584− -- ^ If 'True', record fields with a 'Nothing' value will be
585− -- omitted from the resulting object. If 'False', the resulting
584+ -- ^ If 'True' record fields with a 'Nothing' value will be
585+ -- omitted from the resulting object. If 'False' the resulting
586586 -- object will include those fields mapping to @null@.
587587 --
588− -- Note that this /does not/ affect parsing: 'Maybe' fields are
589− -- optional regardless of the value of 'omitNothingFields', subject
590− -- to the note below.
591− --
592588 -- === Note
593589 --
594590 -- Setting 'omitNothingFields' to 'True' only affects fields which are of
595− -- type 'Maybe' /uniformly/ in the 'ToJSON' instance.
596− -- In particular, if the type of a field is declared as a type variable, it
591+ -- type 'Maybe' /uniformly/ in the 'ToJSON' or 'FromJSON' instance. In
592+ -- particular, if the type of a field is declared as a type variable, it
597593 -- will not be omitted from the JSON object, unless the field is
598594 -- specialized upfront in the instance.
599595 --
600− -- The same holds for 'Maybe' fields being optional in the 'FromJSON' instance.
601− --
602596 -- ==== __Example__
603597 --
604598 -- The generic instance for the following type @Fruit@ depends on whether
605599 -- the instance head is @Fruit a@ or @Fruit (Maybe a)@.
606600 --
607601 -- @
608− -- data Fruit a = Fruit
602+ -- data Fruit a =
609603 -- { apples :: a -- A field whose type is a type variable.
610604 -- , oranges :: 'Maybe' Int
611− -- } deriving 'Generic'
605+ -- }
606+ --
607+ -- options :: 'Options'
608+ -- options = 'defaultOptions' { 'omitNothingFields' = 'True' }
612609 --
613610 -- -- apples required, oranges optional
614611 -- -- Even if 'Data.Aeson.fromJSON' is then specialized to (Fruit ('Maybe' a)).
615− -- instance 'Data.Aeson.FromJSON' a => 'Data.Aeson.FromJSON' (Fruit a)
612+ -- instance 'Data.Aeson.FromJSON' a => 'Data.Aeson.FromJSON' (Fruit a) where
613+ -- 'Data.Aeson.fromJSON' = 'Data.Aeson.genericFromJSON' options
616614 --
617615 -- -- apples optional, oranges optional
618616 -- -- In this instance, the field apples is uniformly of type ('Maybe' a).
619− -- instance 'Data.Aeson.FromJSON' a => 'Data.Aeson.FromJSON' (Fruit ('Maybe' a))
620− --
621− -- options :: 'Options'
622− -- options = 'defaultOptions' { 'omitNothingFields' = 'True' }
623− --
624− -- -- apples always present in the output, oranges is omitted if 'Nothing'
625− -- instance 'Data.Aeson.ToJSON' a => 'Data.Aeson.ToJSON' (Fruit a) where
626− -- 'Data.Aeson.toJSON' = 'Data.Aeson.genericToJSON' options
627− --
628− -- -- both apples and oranges are omitted if 'Nothing'
629− -- instance 'Data.Aeson.ToJSON' a => 'Data.Aeson.ToJSON' (Fruit ('Maybe' a)) where
630− -- 'Data.Aeson.toJSON' = 'Data.Aeson.genericToJSON' options
617+ -- instance 'Data.Aeson.FromJSON' a => 'Data.Aeson.FromJSON' (Fruit ('Maybe' a)) where
618+ -- 'Data.Aeson.fromJSON' = 'Data.Aeson.genericFromJSON' options
631619 -- @
632620 , sumEncoding :: SumEncoding
633621 -- ^ Specifies how to encode constructors of a sum datatype.