@@ -44,7 +44,6 @@ module Data.Aeson.Types.Internal
45 , parseEither
45 , parseEither
46 , parseMaybe
46 , parseMaybe
48 , modifyFailure
47 , modifyFailure
49 , prependFailure
48 , prependFailure
50 , parserThrowError
49 , parserThrowError
@@ -343,10 +342,6 @@ instance Monoid (Parser a) where
343 mappend = (<>)
342 mappend = (<>)
344 {-# INLINE mappend #-}
343 {-# INLINE mappend #-}
346−-- | Raise a parsing failure with some custom message.
347−parseFail :: String -> Parser a
350apP :: Parser (a -> b) -> Parser a -> Parser b
345apP :: Parser (a -> b) -> Parser a -> Parser b
351apP d e = do
346apP d e = do
@@ -586,53 +581,41 @@ data Options = Options
586 -- the constructor tag. If 'False' the encoding will always
581 -- the constructor tag. If 'False' the encoding will always
587 -- follow the `sumEncoding`.
582 -- follow the `sumEncoding`.
588 , omitNothingFields :: Bool
583 , omitNothingFields :: Bool
589− -- ^ If 'True', record fields with a 'Nothing' value will be
584+ -- ^ If 'True' record fields with a 'Nothing' value will be
590− -- omitted from the resulting object. If 'False', the resulting
585+ -- omitted from the resulting object. If 'False' the resulting
591 -- object will include those fields mapping to @null@.
586 -- object will include those fields mapping to @null@.
593− -- Note that this /does not/ affect parsing: 'Maybe' fields are
594− -- optional regardless of the value of 'omitNothingFields', subject
595− -- to the note below.
597 -- === Note
588 -- === Note
599 -- Setting 'omitNothingFields' to 'True' only affects fields which are of
590 -- Setting 'omitNothingFields' to 'True' only affects fields which are of
600− -- type 'Maybe' /uniformly/ in the 'ToJSON' instance.
591+ -- type 'Maybe' /uniformly/ in the 'ToJSON' or 'FromJSON' instance. In
601− -- In particular, if the type of a field is declared as a type variable, it
592+ -- particular, if the type of a field is declared as a type variable, it
602 -- will not be omitted from the JSON object, unless the field is
593 -- will not be omitted from the JSON object, unless the field is
603 -- specialized upfront in the instance.
594 -- specialized upfront in the instance.
605− -- The same holds for 'Maybe' fields being optional in the 'FromJSON' instance.
607 -- ==== __Example__
596 -- ==== __Example__
609 -- The generic instance for the following type @Fruit@ depends on whether
598 -- The generic instance for the following type @Fruit@ depends on whether
610 -- the instance head is @Fruit a@ or @Fruit (Maybe a)@.
599 -- the instance head is @Fruit a@ or @Fruit (Maybe a)@.
613− -- data Fruit a = Fruit
602+ -- data Fruit a =
614 -- { apples :: a -- A field whose type is a type variable.
603 -- { apples :: a -- A field whose type is a type variable.
615 -- , oranges :: 'Maybe' Int
604 -- , oranges :: 'Maybe' Int
616− -- } deriving 'Generic'
605+ -- }
607+ -- options :: 'Options'
608+ -- options = 'defaultOptions' { 'omitNothingFields' = 'True' }
618 -- -- apples required, oranges optional
610 -- -- apples required, oranges optional
619 -- -- Even if 'Data.Aeson.fromJSON' is then specialized to (Fruit ('Maybe' a)).
611 -- -- Even if 'Data.Aeson.fromJSON' is then specialized to (Fruit ('Maybe' a)).
620− -- 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
622 -- -- apples optional, oranges optional
615 -- -- apples optional, oranges optional
623 -- -- In this instance, the field apples is uniformly of type ('Maybe' a).
616 -- -- In this instance, the field apples is uniformly of type ('Maybe' a).
624− -- instance 'Data.Aeson.FromJSON' a => 'Data.Aeson.FromJSON' (Fruit ('Maybe' a))
617+ -- instance 'Data.Aeson.FromJSON' a => 'Data.Aeson.FromJSON' (Fruit ('Maybe' a)) where
625− --
618+ -- 'Data.Aeson.fromJSON' = 'Data.Aeson.genericFromJSON' options
626− -- options :: 'Options'
627− -- options = 'defaultOptions' { 'omitNothingFields' = 'True' }
629− -- -- apples always present in the output, oranges is omitted if 'Nothing'
630− -- instance 'Data.Aeson.ToJSON' a => 'Data.Aeson.ToJSON' (Fruit a) where
631− -- 'Data.Aeson.toJSON' = 'Data.Aeson.genericToJSON' options
633− -- -- both apples and oranges are omitted if 'Nothing'
634− -- instance 'Data.Aeson.ToJSON' a => 'Data.Aeson.ToJSON' (Fruit ('Maybe' a)) where
635− -- 'Data.Aeson.toJSON' = 'Data.Aeson.genericToJSON' options
637 , sumEncoding :: SumEncoding
620 , sumEncoding :: SumEncoding
638 -- ^ Specifies how to encode constructors of a sum datatype.
621 -- ^ Specifies how to encode constructors of a sum datatype.