basvandijk avatar basvandijk committed a7df467

Renamed valueFieldName to contentsFieldName
This reflects its purpose more accurately.

Comments (0)

Files changed (3)

         case sumEncoding opts of
           TwoElemArray ->
               [|Array|] `appE` ([|V.fromList|] `appE` listE [conStr opts conName, exp])
-          ObjectWithType{typeFieldName, valueFieldName} ->
+          ObjectWithType{typeFieldName, contentsFieldName} ->
               [|object|] `appE` listE
-                [ infixApp [|T.pack typeFieldName|]  [|(.=)|] (conStr opts conName)
-                , infixApp [|T.pack valueFieldName|] [|(.=)|] exp
+                [ infixApp [|T.pack typeFieldName|]     [|(.=)|] (conStr opts conName)
+                , infixApp [|T.pack contentsFieldName|] [|(.=)|] exp
                 ]
           ObjectWithSingleField ->
               [|object|] `appE` listE
 
     mixedMatches =
         case sumEncoding opts of
-          ObjectWithType {typeFieldName, valueFieldName} ->
-            parseObject $ parseObjectWithType typeFieldName valueFieldName
+          ObjectWithType {typeFieldName, contentsFieldName} ->
+            parseObject $ parseObjectWithType typeFieldName contentsFieldName
           ObjectWithSingleField ->
             parseObject $ parseObjectWithSingleField
           TwoElemArray ->

Data/Aeson/Types/Generic.hs

 nonAllNullarySumToJSON opts =
     case sumEncoding opts of
       ObjectWithType{..}    -> object . objectWithType opts typeFieldName
-                                                            valueFieldName
+                                                            contentsFieldName
       ObjectWithSingleField -> Object . objectWithSingleField opts
       TwoElemArray          -> Array  . twoElemArray opts
 {-# INLINE nonAllNullarySumToJSON #-}
 
 instance ( ObjectWithType a
          , ObjectWithType b ) => ObjectWithType (a :+: b) where
-    objectWithType     opts typeFieldName valueFieldName (L1 x) =
-        objectWithType opts typeFieldName valueFieldName     x
-    objectWithType     opts typeFieldName valueFieldName (R1 x) =
-        objectWithType opts typeFieldName valueFieldName     x
+    objectWithType     opts typeFieldName contentsFieldName (L1 x) =
+        objectWithType opts typeFieldName contentsFieldName     x
+    objectWithType     opts typeFieldName contentsFieldName (R1 x) =
+        objectWithType opts typeFieldName contentsFieldName     x
     {-# INLINE objectWithType #-}
 
 instance ( IsRecord        a isRecord
          , ObjectWithType' a isRecord
          , Constructor c ) => ObjectWithType (C1 c a) where
-    objectWithType opts typeFieldName valueFieldName =
+    objectWithType opts typeFieldName contentsFieldName =
         (pack typeFieldName .= constructorNameModifier opts
                                  (conName (undefined :: t c a p)) :) .
         (unTagged :: Tagged isRecord [Pair] -> [Pair]) .
-          objectWithType' opts valueFieldName . unM1
+          objectWithType' opts contentsFieldName . unM1
     {-# INLINE objectWithType #-}
 
 class ObjectWithType' f isRecord where
     {-# INLINE objectWithType' #-}
 
 instance (GToJSON f) => ObjectWithType' f False where
-    objectWithType' opts valueFieldName =
-        Tagged . (:[]) . (pack valueFieldName .=) . gToJSON opts
+    objectWithType' opts contentsFieldName =
+        Tagged . (:[]) . (pack contentsFieldName .=) . gToJSON opts
     {-# INLINE objectWithType' #-}
 
 --------------------------------------------------------------------------------
           withObject "Object" $ \obj -> do
             key <- obj .: pack typeFieldName
             fromMaybe (notFound $ unpack key) $
-              parseFromObjectWithType opts valueFieldName obj key
+              parseFromObjectWithType opts contentsFieldName obj key
 
       ObjectWithSingleField ->
           withObject "Object" $ \obj ->
 
 instance (FromObjectWithType a, FromObjectWithType b) =>
     FromObjectWithType (a :+: b) where
-        parseFromObjectWithType opts valueFieldName obj key =
-            (fmap L1 <$> parseFromObjectWithType opts valueFieldName obj key) <|>
-            (fmap R1 <$> parseFromObjectWithType opts valueFieldName obj key)
+        parseFromObjectWithType opts contentsFieldName obj key =
+            (fmap L1 <$> parseFromObjectWithType opts contentsFieldName obj key) <|>
+            (fmap R1 <$> parseFromObjectWithType opts contentsFieldName obj key)
         {-# INLINE parseFromObjectWithType #-}
 
 instance ( FromObjectWithType' f
          , Constructor c ) => FromObjectWithType (C1 c f) where
-    parseFromObjectWithType opts valueFieldName obj key
+    parseFromObjectWithType opts contentsFieldName obj key
         | key == name = Just $ M1 <$> parseFromObjectWithType'
-                                        opts valueFieldName obj
+                                        opts contentsFieldName obj
         | otherwise = Nothing
         where
           name = pack $ constructorNameModifier opts $
 instance ( IsRecord               f isRecord
          , FromObjectWithType''   f isRecord
          ) => FromObjectWithType' f where
-    parseFromObjectWithType' opts valueFieldName =
+    parseFromObjectWithType' opts contentsFieldName =
         (unTagged :: Tagged isRecord (Parser (f a)) -> Parser (f a)) .
-        parseFromObjectWithType'' opts valueFieldName
+        parseFromObjectWithType'' opts contentsFieldName
     {-# INLINE parseFromObjectWithType' #-}
 
 instance (FromRecord f) => FromObjectWithType'' f True where
     {-# INLINE parseFromObjectWithType'' #-}
 
 instance (GFromJSON f) => FromObjectWithType'' f False where
-    parseFromObjectWithType'' opts valueFieldName = Tagged .
-      (gParseJSON opts <=< (.: pack valueFieldName))
+    parseFromObjectWithType'' opts contentsFieldName = Tagged .
+      (gParseJSON opts <=< (.: pack contentsFieldName))
     {-# INLINE parseFromObjectWithType'' #-}
 
 --------------------------------------------------------------------------------

Data/Aeson/Types/Internal.hs

 
 -- | Specifies how to encode constructors of a sum datatype.
 data SumEncoding =
-    ObjectWithType { typeFieldName  :: String
-                   , valueFieldName :: String
+    ObjectWithType { typeFieldName     :: String
+                   , contentsFieldName :: String
                    }
     -- ^ A constructor will be encoded to an object with a field
     -- 'typeFieldName' which specifies the constructor name (modified
     -- record the encoded record fields will be unpacked into this
     -- object. So make sure that your record doesn't have a field with
     -- the same name as the 'typeFieldName'. Otherwise the type gets
-    -- overwritten by that field. If the constructor is not a record
-    -- the encoded constructor content will be stored under the
-    -- 'valueFieldName' field.
+    -- overwritten by that field! If the constructor is not a record
+    -- the encoded constructor contents will be stored under the
+    -- 'contentsFieldName' field.
   | ObjectWithSingleField
     -- ^ A constructor will be encoded to an object with a single
     -- field named after the constructor (modified by the
     -- ^ A constructor will be encoded to a 2-element array where the
     -- first element is the name of the constructor (modified by the
     -- 'constructorNameModifier') and the second element the encoded
-    -- content of the constructor.
+    -- contents of the constructor.
 
 -- | Default encoding 'Options':
 --
 --
 -- @
 -- defaultObjectWithType = 'ObjectWithType'
---                         { 'typeFieldName'  = \"type\"
---                         , 'valueFieldName' = \"value\"
+--                         { 'typeFieldName'     = \"type\"
+--                         , 'contentsFieldName' = \"contents\"
 --                         }
 -- @
 defaultObjectWithType :: SumEncoding
 defaultObjectWithType = ObjectWithType
-                        { typeFieldName  = "type"
-                        , valueFieldName = "value"
+                        { typeFieldName     = "type"
+                        , contentsFieldName = "contents"
                         }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.