Commits

basvandijk  committed 07a6c92

Renamed fieldNameModifier to the more accurate fieldLabelModifier

  • Participants
  • Parent commits d88380d

Comments (0)

Files changed (3)

File Data/Aeson/TH.hs

 lower-casing them:
 
 @
-$('deriveJSON' 'defaultOptions'{'fieldNameModifier' = 'drop' 4, 'constructorTagModifier' = map toLower} ''D)
+$('deriveJSON' 'defaultOptions'{'fieldLabelModifier' = 'drop' 4, 'constructorTagModifier' = map toLower} ''D)
 @
 
 Now we can use the newly created instances.
                      [|(.=)|]
                      (varE arg)
 
-        toFieldName field = [|T.pack|] `appE` fieldNameExp opts field
+        toFieldName field = [|T.pack|] `appE` fieldLabelExp opts field
 
     match (conP conName $ map varP args)
           ( normalB
                `appE` (litE $ stringL $ show tName)
                `appE` (litE $ stringL $ constructorTagModifier opts $ nameBase conName)
                `appE` (varE obj)
-               `appE` ( [|T.pack|] `appE` fieldNameExp opts field
+               `appE` ( [|T.pack|] `appE` fieldLabelExp opts field
                       )
              | (field, _, _) <- ts
              ]
                 . nameBase
                 . getConName
 
--- | Creates a string literal expression from a record field name.
-fieldNameExp :: Options -- ^ Encoding options
-             -> Name
-             -> Q Exp
-fieldNameExp opts = litE . stringL . fieldNameModifier opts . nameBase
+-- | Creates a string literal expression from a record field label.
+fieldLabelExp :: Options -- ^ Encoding options
+              -> Name
+              -> Q Exp
+fieldLabelExp opts = litE . stringL . fieldLabelModifier opts . nameBase
 
 -- | The name of the outermost 'Value' constructor.
 valueConName :: Value -> String

File Data/Aeson/Types/Generic.hs

     {-# INLINE recordToPairs #-}
 
 fieldToPair :: (Selector s, GToJSON a) => Options -> S1 s a p -> DList Pair
-fieldToPair opts m1 = pure ( pack $ fieldNameModifier opts $ selName m1
+fieldToPair opts m1 = pure ( pack $ fieldLabelModifier opts $ selName m1
                            , gToJSON opts (unM1 m1)
                            )
 {-# INLINE fieldToPair #-}
     {-# INLINE parseRecord #-}
 
 instance (Selector s, GFromJSON a) => FromRecord (S1 s a) where
-    parseRecord opts = maybe (notFound key) (gParseJSON opts)
-                      . H.lookup (pack key)
+    parseRecord opts = maybe (notFound label) (gParseJSON opts)
+                      . H.lookup (pack label)
         where
-          key = fieldNameModifier opts $ selName (undefined :: t s a p)
+          label = fieldLabelModifier opts $ selName (undefined :: t s a p)
     {-# INLINE parseRecord #-}
 
 instance (Selector s, FromJSON a) => FromRecord (S1 s (K1 i (Maybe a))) where
-    parseRecord opts obj = (M1 . K1) <$> obj .:? pack key
+    parseRecord opts obj = (M1 . K1) <$> obj .:? pack label
         where
-          key = fieldNameModifier opts $
-                  selName (undefined :: t s (K1 i (Maybe a)) p)
+          label = fieldLabelModifier opts $
+                    selName (undefined :: t s (K1 i (Maybe a)) p)
     {-# INLINE parseRecord #-}
 
 --------------------------------------------------------------------------------

File Data/Aeson/Types/Internal.hs

 
 -- | Options that specify how to encode\/decode your datatype to\/from JSON.
 data Options = Options
-    { fieldNameModifier :: String -> String
-      -- ^ Function applied to field names.
+    { fieldLabelModifier :: String -> String
+      -- ^ Function applied to field labels.
       -- Handy for removing common record prefixes for example.
     , constructorTagModifier :: String -> String
       -- ^ Function applied to constructor tags which could be handy
 --
 -- @
 -- 'Options'
--- { 'fieldNameModifier'       = id
+-- { 'fieldLabelModifier'      = id
 -- , 'constructorTagModifier'  = id
 -- , 'nullaryToString'         = True
 -- , 'omitNothingFields'       = False
 -- @
 defaultOptions :: Options
 defaultOptions = Options
-                 { fieldNameModifier       = id
+                 { fieldLabelModifier      = id
                  , constructorTagModifier  = id
                  , nullaryToString         = True
                  , omitNothingFields       = False