on master help sign in
3 files changed+15−34
since splitsnapshots
unifiedsplit
Data/Aeson.hs+2−2 Data/Aeson/Types.hs−1 Data/Aeson/Types/Internal.hs+13−31
Data/Aeson.hs+2−2
@@ -257,7 +257,7 @@ eitherDecodeStrict =
257257-- | Like 'decodeFileStrict' but returns an error message when decoding fails.
258258eitherDecodeFileStrict :: (FromJSON a) => FilePath -> IO (Either String a)
259259eitherDecodeFileStrict =
260− fmap eitherDecodeStrict . B.readFile
260+ fmap (eitherFormatError . eitherDecodeStrictWith jsonEOF ifromJSON) . B.readFile
261261{-# INLINE eitherDecodeFileStrict #-}
262262
263263-- | Like 'decode'' but returns an error message when decoding fails.
@@ -274,7 +274,7 @@ eitherDecodeStrict' =
274274-- | Like 'decodeFileStrict'' but returns an error message when decoding fails.
275275eitherDecodeFileStrict' :: (FromJSON a) => FilePath -> IO (Either String a)
276276eitherDecodeFileStrict' =
277− fmap eitherDecodeStrict' . B.readFile
277+ fmap (eitherFormatError . eitherDecodeStrictWith jsonEOF' ifromJSON) . B.readFile
278278{-# INLINE eitherDecodeFileStrict' #-}
279279
280280-- $use
Data/Aeson/Types.hs−1
@@ -35,7 +35,6 @@ module Data.Aeson.Types
3535 , parse
3636 , parseEither
3737 , parseMaybe
38− , parseFail
3938 , ToJSON(..)
4039 , KeyValue(..)
4140 , modifyFailure
Data/Aeson/Types/Internal.hs+13−31
@@ -44,7 +44,6 @@ module Data.Aeson.Types.Internal
4444 , parse
4545 , parseEither
4646 , parseMaybe
47− , parseFail
4847 , modifyFailure
4948 , prependFailure
5049 , parserThrowError
@@ -343,11 +342,6 @@ instance Monoid (Parser a) where
343342 mappend = (<>)
344343 {-# INLINE mappend #-}
345344
346−-- | Raise a parsing failure with some custom message.
347−parseFail :: String -> Parser a
348−parseFail = fail
349−{-# INLINE parseFail #-}
350−
351345apP :: Parser (a -> b) -> Parser a -> Parser b
352346apP d e = do
353347 b <- d
@@ -587,53 +581,41 @@ data Options = Options
587581 -- the constructor tag. If 'False' the encoding will always
588582 -- follow the `sumEncoding`.
589583 , omitNothingFields :: Bool
590− -- ^ If 'True', record fields with a 'Nothing' value will be
591− -- 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
592586 -- object will include those fields mapping to @null@.
593587 --
594− -- Note that this /does not/ affect parsing: 'Maybe' fields are
595− -- optional regardless of the value of 'omitNothingFields', subject
596− -- to the note below.
597− --
598588 -- === Note
599589 --
600590 -- Setting 'omitNothingFields' to 'True' only affects fields which are of
601− -- type 'Maybe' /uniformly/ in the 'ToJSON' instance.
602− -- 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
603593 -- will not be omitted from the JSON object, unless the field is
604594 -- specialized upfront in the instance.
605595 --
606− -- The same holds for 'Maybe' fields being optional in the 'FromJSON' instance.
607− --
608596 -- ==== __Example__
609597 --
610598 -- The generic instance for the following type @Fruit@ depends on whether
611599 -- the instance head is @Fruit a@ or @Fruit (Maybe a)@.
612600 --
613601 -- @
614− -- data Fruit a = Fruit
602+ -- data Fruit a =
615603 -- { apples :: a -- A field whose type is a type variable.
616604 -- , oranges :: 'Maybe' Int
617− -- } deriving 'Generic'
605+ -- }
606+ --
607+ -- options :: 'Options'
608+ -- options = 'defaultOptions' { 'omitNothingFields' = 'True' }
618609 --
619610 -- -- apples required, oranges optional
620611 -- -- Even if 'Data.Aeson.fromJSON' is then specialized to (Fruit ('Maybe' a)).
621− -- 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
622614 --
623615 -- -- apples optional, oranges optional
624616 -- -- In this instance, the field apples is uniformly of type ('Maybe' a).
625− -- instance 'Data.Aeson.FromJSON' a => 'Data.Aeson.FromJSON' (Fruit ('Maybe' a))
626− --
627− -- options :: 'Options'
628− -- options = 'defaultOptions' { 'omitNothingFields' = 'True' }
629− --
630− -- -- apples always present in the output, oranges is omitted if 'Nothing'
631− -- instance 'Data.Aeson.ToJSON' a => 'Data.Aeson.ToJSON' (Fruit a) where
632− -- 'Data.Aeson.toJSON' = 'Data.Aeson.genericToJSON' options
633− --
634− -- -- both apples and oranges are omitted if 'Nothing'
635− -- instance 'Data.Aeson.ToJSON' a => 'Data.Aeson.ToJSON' (Fruit ('Maybe' a)) where
636− -- '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
637619 -- @
638620 , sumEncoding :: SumEncoding
639621 -- ^ Specifies how to encode constructors of a sum datatype.