on master help sign in
Track JSONPath in derived parsers
cdf6db1lyxia
Data/Aeson/TH.hs+2−2
@@ -107,7 +107,7 @@ import Data.Aeson.Types ( Value(..), Parser
107 , defaultOptions
107 , defaultOptions
108 , defaultTaggedObject
108 , defaultTaggedObject
109 )
109 )
110−import Data.Aeson.Types.Internal (Encoding(..))
110+import Data.Aeson.Types.Internal (Encoding(..), (<?>), JSONPathElement(Key))
111import Control.Monad ( liftM2, return, mapM, fail )
111import Control.Monad ( liftM2, return, mapM, fail )
112import Data.Bool ( Bool(False, True), otherwise, (&&), not )
112import Data.Bool ( Bool(False, True), otherwise, (&&), not )
113import Data.Either ( Either(Left, Right) )
113import Data.Either ( Either(Left, Right) )
@@ -1010,7 +1010,7 @@ instance OVERLAPPABLE_ (FromJSON a) => LookupField a where
1010 lookupField tName rec obj key =
1010 lookupField tName rec obj key =
1011 case H.lookup key obj of
1011 case H.lookup key obj of
1012 Nothing -> unknownFieldFail tName rec (T.unpack key)
1012 Nothing -> unknownFieldFail tName rec (T.unpack key)
1013− Just v -> parseJSON v
1013+ Just v -> parseJSON v <?> Key key
1014
1014
1015instance (FromJSON a) => LookupField (Maybe a) where
1015instance (FromJSON a) => LookupField (Maybe a) where
1016 lookupField _ _ = (.:?)
1016 lookupField _ _ = (.:?)
Data/Aeson/Types/Generic.hs+4−5
@@ -679,12 +679,11 @@ instance (FromRecord a, FromRecord b) => FromRecord (a :*: b) where
679 <*> parseRecord opts Nothing obj
679 <*> parseRecord opts Nothing obj
680
680
681instance (Selector s, GFromJSON a) => FromRecord (S1 s a) where
681instance (Selector s, GFromJSON a) => FromRecord (S1 s a) where
682− parseRecord opts (Just lab) = maybe (notFound $ unpack lab)
682+ parseRecord opts lab = (<?> Key label) . gParseJSON opts <=< (.: label)
683− (gParseJSON opts) . H.lookup lab
684− parseRecord opts Nothing = maybe (notFound label)
685− (gParseJSON opts) . H.lookup (pack label)
686 where
683 where
684+ label = fromMaybe defLabel lab
685+ defLabel = pack . fieldLabelModifier opts $
687− label = fieldLabelModifier opts $ selName (undefined :: t s a p)
686+ selName (undefined :: t s a p)
688
687
689instance OVERLAPPING_ (Selector s, FromJSON a) =>
688instance OVERLAPPING_ (Selector s, FromJSON a) =>
690 FromRecord (S1 s (K1 i (Maybe a))) where
689 FromRecord (S1 s (K1 i (Maybe a))) where