on master help sign in
Renamed fieldNameModifier to the more accurate fieldLabelModifier
0ec4f5dBas van Dijk
Data/Aeson/TH.hs+8−8
@@ -33,7 +33,7 @@ characters of every field name. We also modify constructor names by
33lower-casing them:
33lower-casing them:
34
34
35@
35@
36−$('deriveJSON' 'defaultOptions'{'fieldNameModifier' = 'drop' 4, 'constructorTagModifier' = map toLower} ''D)
36+$('deriveJSON' 'defaultOptions'{'fieldLabelModifier' = 'drop' 4, 'constructorTagModifier' = map toLower} ''D)
37@
37@
38
38
39Now we can use the newly created instances.
39Now we can use the newly created instances.
@@ -317,7 +317,7 @@ encodeArgs opts multiCons (RecC conName ts) = do
317 [|(.=)|]
317 [|(.=)|]
318 (varE arg)
318 (varE arg)
319
319
320− toFieldName field = [|T.pack|] `appE` fieldNameExp opts field
320+ toFieldName field = [|T.pack|] `appE` fieldLabelExp opts field
321
321
322 match (conP conName $ map varP args)
322 match (conP conName $ map varP args)
323 ( normalB
323 ( normalB
@@ -625,7 +625,7 @@ parseRecord opts tName conName ts obj =
625 `appE` (litE $ stringL $ show tName)
625 `appE` (litE $ stringL $ show tName)
626 `appE` (litE $ stringL $ constructorTagModifier opts $ nameBase conName)
626 `appE` (litE $ stringL $ constructorTagModifier opts $ nameBase conName)
627 `appE` (varE obj)
627 `appE` (varE obj)
628− `appE` ( [|T.pack|] `appE` fieldNameExp opts field
628+ `appE` ( [|T.pack|] `appE` fieldLabelExp opts field
629 )
629 )
630 | (field, _, _) <- ts
630 | (field, _, _) <- ts
631 ]
631 ]
@@ -858,11 +858,11 @@ conNameExp opts = litE
858 . nameBase
858 . nameBase
859 . getConName
859 . getConName
860
860
861−-- | Creates a string literal expression from a record field name.
861+-- | Creates a string literal expression from a record field label.
862−fieldNameExp :: Options -- ^ Encoding options
862+fieldLabelExp :: Options -- ^ Encoding options
863− -> Name
863+ -> Name
864− -> Q Exp
864+ -> Q Exp
865−fieldNameExp opts = litE . stringL . fieldNameModifier opts . nameBase
865+fieldLabelExp opts = litE . stringL . fieldLabelModifier opts . nameBase
866
866
867-- | The name of the outermost 'Value' constructor.
867-- | The name of the outermost 'Value' constructor.
868valueConName :: Value -> String
868valueConName :: Value -> String
Data/Aeson/Types/Generic.hs+7−7
@@ -228,7 +228,7 @@ instance (Selector s, ToJSON a) => RecordToPairs (S1 s (K1 i (Maybe a))) where
228 {-# INLINE recordToPairs #-}
228 {-# INLINE recordToPairs #-}
229
229
230fieldToPair :: (Selector s, GToJSON a) => Options -> S1 s a p -> DList Pair
230fieldToPair :: (Selector s, GToJSON a) => Options -> S1 s a p -> DList Pair
231−fieldToPair opts m1 = pure ( pack $ fieldNameModifier opts $ selName m1
231+fieldToPair opts m1 = pure ( pack $ fieldLabelModifier opts $ selName m1
232 , gToJSON opts (unM1 m1)
232 , gToJSON opts (unM1 m1)
233 )
233 )
234{-# INLINE fieldToPair #-}
234{-# INLINE fieldToPair #-}
@@ -490,17 +490,17 @@ instance (FromRecord a, FromRecord b) => FromRecord (a :*: b) where
490 {-# INLINE parseRecord #-}
490 {-# INLINE parseRecord #-}
491
491
492instance (Selector s, GFromJSON a) => FromRecord (S1 s a) where
492instance (Selector s, GFromJSON a) => FromRecord (S1 s a) where
493− parseRecord opts = maybe (notFound key) (gParseJSON opts)
493+ parseRecord opts = maybe (notFound label) (gParseJSON opts)
494− . H.lookup (pack key)
494+ . H.lookup (pack label)
495 where
495 where
496− key = fieldNameModifier opts $ selName (undefined :: t s a p)
496+ label = fieldLabelModifier opts $ selName (undefined :: t s a p)
497 {-# INLINE parseRecord #-}
497 {-# INLINE parseRecord #-}
498
498
499instance (Selector s, FromJSON a) => FromRecord (S1 s (K1 i (Maybe a))) where
499instance (Selector s, FromJSON a) => FromRecord (S1 s (K1 i (Maybe a))) where
500− parseRecord opts obj = (M1 . K1) <$> obj .:? pack key
500+ parseRecord opts obj = (M1 . K1) <$> obj .:? pack label
501 where
501 where
502− key = fieldNameModifier opts $
502+ label = fieldLabelModifier opts $
503− selName (undefined :: t s (K1 i (Maybe a)) p)
503+ selName (undefined :: t s (K1 i (Maybe a)) p)
504 {-# INLINE parseRecord #-}
504 {-# INLINE parseRecord #-}
505
505
506--------------------------------------------------------------------------------
506--------------------------------------------------------------------------------
Data/Aeson/Types/Internal.hs+4−4
@@ -251,8 +251,8 @@ modifyFailure f (Parser p) = Parser $ \kf -> p (kf . f)
251
251
252-- | Options that specify how to encode\/decode your datatype to\/from JSON.
252-- | Options that specify how to encode\/decode your datatype to\/from JSON.
253data Options = Options
253data Options = Options
254− { fieldNameModifier :: String -> String
254+ { fieldLabelModifier :: String -> String
255− -- ^ Function applied to field names.
255+ -- ^ Function applied to field labels.
256 -- Handy for removing common record prefixes for example.
256 -- Handy for removing common record prefixes for example.
257 , constructorTagModifier :: String -> String
257 , constructorTagModifier :: String -> String
258 -- ^ Function applied to constructor tags which could be handy
258 -- ^ Function applied to constructor tags which could be handy
@@ -299,7 +299,7 @@ data SumEncoding =
299--
299--
300-- @
300-- @
301-- 'Options'
301-- 'Options'
302−-- { 'fieldNameModifier' = id
302+-- { 'fieldLabelModifier' = id
303-- , 'constructorTagModifier' = id
303-- , 'constructorTagModifier' = id
304-- , 'nullaryToString' = True
304-- , 'nullaryToString' = True
305-- , 'omitNothingFields' = False
305-- , 'omitNothingFields' = False
@@ -308,7 +308,7 @@ data SumEncoding =
308-- @
308-- @
309defaultOptions :: Options
309defaultOptions :: Options
310defaultOptions = Options
310defaultOptions = Options
311− { fieldNameModifier = id
311+ { fieldLabelModifier = id
312 , constructorTagModifier = id
312 , constructorTagModifier = id
313 , nullaryToString = True
313 , nullaryToString = True
314 , omitNothingFields = False
314 , omitNothingFields = False