@@ -44,7 +44,6 @@ module Data.Aeson.Types.Internal
4444 , parse
4545 , parseEither
4646 , parseMaybe
47− , parseFail
4847 , modifyFailure
4948 , prependFailure
5049 , parserThrowError
@@ -95,6 +94,7 @@ import Data.HashMap.Strict (HashMap)
9594import Data.Hashable (Hashable(..))
9695import Data.List (intercalate)
9796import Data.Scientific (Scientific)
97+import Data.Semigroup (Semigroup((<>)))
9898import Data.String (IsString(..))
9999import Data.Text (Text, pack, unpack)
100100import Data.Time (UTCTime)
@@ -342,10 +342,6 @@ instance Monoid (Parser a) where
342342 mappend = (<>)
343343 {-# INLINE mappend #-}
344344
345−-- | Raise a parsing failure with some custom message.
346−parseFail :: String -> Parser a
347−parseFail = fail
348−
349345apP :: Parser (a -> b) -> Parser a -> Parser b
350346apP d e = do
351347 b <- d
@@ -585,53 +581,41 @@ data Options = Options
585581 -- the constructor tag. If 'False' the encoding will always
586582 -- follow the `sumEncoding`.
587583 , omitNothingFields :: Bool
588− -- ^ If 'True', record fields with a 'Nothing' value will be
589− -- 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
590586 -- object will include those fields mapping to @null@.
591587 --
592− -- Note that this /does not/ affect parsing: 'Maybe' fields are
593− -- optional regardless of the value of 'omitNothingFields', subject
594− -- to the note below.
595− --
596588 -- === Note
597589 --
598590 -- Setting 'omitNothingFields' to 'True' only affects fields which are of
599− -- type 'Maybe' /uniformly/ in the 'ToJSON' instance.
600− -- 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
601593 -- will not be omitted from the JSON object, unless the field is
602594 -- specialized upfront in the instance.
603595 --
604− -- The same holds for 'Maybe' fields being optional in the 'FromJSON' instance.
605− --
606596 -- ==== __Example__
607597 --
608598 -- The generic instance for the following type @Fruit@ depends on whether
609599 -- the instance head is @Fruit a@ or @Fruit (Maybe a)@.
610600 --
611601 -- @
612− -- data Fruit a = Fruit
602+ -- data Fruit a =
613603 -- { apples :: a -- A field whose type is a type variable.
614604 -- , oranges :: 'Maybe' Int
615− -- } deriving 'Generic'
605+ -- }
606+ --
607+ -- options :: 'Options'
608+ -- options = 'defaultOptions' { 'omitNothingFields' = 'True' }
616609 --
617610 -- -- apples required, oranges optional
618611 -- -- Even if 'Data.Aeson.fromJSON' is then specialized to (Fruit ('Maybe' a)).
619− -- 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
620614 --
621615 -- -- apples optional, oranges optional
622616 -- -- In this instance, the field apples is uniformly of type ('Maybe' a).
623− -- instance 'Data.Aeson.FromJSON' a => 'Data.Aeson.FromJSON' (Fruit ('Maybe' a))
624− --
625− -- options :: 'Options'
626− -- options = 'defaultOptions' { 'omitNothingFields' = 'True' }
627− --
628− -- -- apples always present in the output, oranges is omitted if 'Nothing'
629− -- instance 'Data.Aeson.ToJSON' a => 'Data.Aeson.ToJSON' (Fruit a) where
630− -- 'Data.Aeson.toJSON' = 'Data.Aeson.genericToJSON' options
631− --
632− -- -- both apples and oranges are omitted if 'Nothing'
633− -- instance 'Data.Aeson.ToJSON' a => 'Data.Aeson.ToJSON' (Fruit ('Maybe' a)) where
634− -- '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
635619 -- @
636620 , sumEncoding :: SumEncoding
637621 -- ^ Specifies how to encode constructors of a sum datatype.