on master help sign in
Renamed valueFieldName to contentsFieldName

This reflects its purpose more accurately.

commit00ebbbedc4188eb502ebb644dafa96710dcfa2f6 authorBas van Dijk <v.dijk.bas@gmail.com> dateTue 23 Apr 2013, 00:53 (13 years ago) parent5bf02dc
3 files changed+34−34
Data/Aeson/TH.hs+5−5 Data/Aeson/Types/Generic.hs+19−19 Data/Aeson/Types/Internal.hs+10−10
Data/Aeson/TH.hs+5−5
@@ -234,10 +234,10 @@ encodeSum opts multiCons conName exp
234234 case sumEncoding opts of
235235 TwoElemArray ->
236236 [|Array|] `appE` ([|V.fromList|] `appE` listE [conStr opts conName, exp])
237− ObjectWithType{typeFieldName, valueFieldName} ->
237+ ObjectWithType{typeFieldName, contentsFieldName} ->
238238 [|object|] `appE` listE
239− [ infixApp [|T.pack typeFieldName|] [|(.=)|] (conStr opts conName)
240− , infixApp [|T.pack valueFieldName|] [|(.=)|] exp
239+ [ infixApp [|T.pack typeFieldName|] [|(.=)|] (conStr opts conName)
240+ , infixApp [|T.pack contentsFieldName|] [|(.=)|] exp
241241 ]
242242 ObjectWithSingleField ->
243243 [|object|] `appE` listE
@@ -454,8 +454,8 @@ consFromJSON tName opts cons = do
454454
455455 mixedMatches =
456456 case sumEncoding opts of
457− ObjectWithType {typeFieldName, valueFieldName} ->
458− parseObject $ parseObjectWithType typeFieldName valueFieldName
457+ ObjectWithType {typeFieldName, contentsFieldName} ->
458+ parseObject $ parseObjectWithType typeFieldName contentsFieldName
459459 ObjectWithSingleField ->
460460 parseObject $ parseObjectWithSingleField
461461 TwoElemArray ->
Data/Aeson/Types/Generic.hs+19−19
@@ -110,7 +110,7 @@ nonAllNullarySumToJSON :: ( TwoElemArray f
110110nonAllNullarySumToJSON opts =
111111 case sumEncoding opts of
112112 ObjectWithType{..} -> object . objectWithType opts typeFieldName
113− valueFieldName
113+ contentsFieldName
114114 ObjectWithSingleField -> Object . objectWithSingleField opts
115115 TwoElemArray -> Array . twoElemArray opts
116116{-# INLINE nonAllNullarySumToJSON #-}
@@ -122,20 +122,20 @@ class ObjectWithType f where
122122
123123instance ( ObjectWithType a
124124 , ObjectWithType b ) => ObjectWithType (a :+: b) where
125− objectWithType opts typeFieldName valueFieldName (L1 x) =
126− objectWithType opts typeFieldName valueFieldName x
127− objectWithType opts typeFieldName valueFieldName (R1 x) =
128− objectWithType opts typeFieldName valueFieldName x
125+ objectWithType opts typeFieldName contentsFieldName (L1 x) =
126+ objectWithType opts typeFieldName contentsFieldName x
127+ objectWithType opts typeFieldName contentsFieldName (R1 x) =
128+ objectWithType opts typeFieldName contentsFieldName x
129129 {-# INLINE objectWithType #-}
130130
131131instance ( IsRecord a isRecord
132132 , ObjectWithType' a isRecord
133133 , Constructor c ) => ObjectWithType (C1 c a) where
134− objectWithType opts typeFieldName valueFieldName =
134+ objectWithType opts typeFieldName contentsFieldName =
135135 (pack typeFieldName .= constructorNameModifier opts
136136 (conName (undefined :: t c a p)) :) .
137137 (unTagged :: Tagged isRecord [Pair] -> [Pair]) .
138− objectWithType' opts valueFieldName . unM1
138+ objectWithType' opts contentsFieldName . unM1
139139 {-# INLINE objectWithType #-}
140140
141141class ObjectWithType' f isRecord where
@@ -146,8 +146,8 @@ instance (RecordToPairs f) => ObjectWithType' f True where
146146 {-# INLINE objectWithType' #-}
147147
148148instance (GToJSON f) => ObjectWithType' f False where
149− objectWithType' opts valueFieldName =
150− Tagged . (:[]) . (pack valueFieldName .=) . gToJSON opts
149+ objectWithType' opts contentsFieldName =
150+ Tagged . (:[]) . (pack contentsFieldName .=) . gToJSON opts
151151 {-# INLINE objectWithType' #-}
152152
153153--------------------------------------------------------------------------------
@@ -387,7 +387,7 @@ parseNonAllNullarySum opts =
387387 withObject "Object" $ \obj -> do
388388 key <- obj .: pack typeFieldName
389389 fromMaybe (notFound $ unpack key) $
390− parseFromObjectWithType opts valueFieldName obj key
390+ parseFromObjectWithType opts contentsFieldName obj key
391391
392392 ObjectWithSingleField ->
393393 withObject "Object" $ \obj ->
@@ -414,16 +414,16 @@ class FromObjectWithType f where
414414
415415instance (FromObjectWithType a, FromObjectWithType b) =>
416416 FromObjectWithType (a :+: b) where
417− parseFromObjectWithType opts valueFieldName obj key =
418− (fmap L1 <$> parseFromObjectWithType opts valueFieldName obj key) <|>
419− (fmap R1 <$> parseFromObjectWithType opts valueFieldName obj key)
417+ parseFromObjectWithType opts contentsFieldName obj key =
418+ (fmap L1 <$> parseFromObjectWithType opts contentsFieldName obj key) <|>
419+ (fmap R1 <$> parseFromObjectWithType opts contentsFieldName obj key)
420420 {-# INLINE parseFromObjectWithType #-}
421421
422422instance ( FromObjectWithType' f
423423 , Constructor c ) => FromObjectWithType (C1 c f) where
424− parseFromObjectWithType opts valueFieldName obj key
424+ parseFromObjectWithType opts contentsFieldName obj key
425425 | key == name = Just $ M1 <$> parseFromObjectWithType'
426− opts valueFieldName obj
426+ opts contentsFieldName obj
427427 | otherwise = Nothing
428428 where
429429 name = pack $ constructorNameModifier opts $
@@ -442,9 +442,9 @@ class FromObjectWithType'' f isRecord where
442442instance ( IsRecord f isRecord
443443 , FromObjectWithType'' f isRecord
444444 ) => FromObjectWithType' f where
445− parseFromObjectWithType' opts valueFieldName =
445+ parseFromObjectWithType' opts contentsFieldName =
446446 (unTagged :: Tagged isRecord (Parser (f a)) -> Parser (f a)) .
447− parseFromObjectWithType'' opts valueFieldName
447+ parseFromObjectWithType'' opts contentsFieldName
448448 {-# INLINE parseFromObjectWithType' #-}
449449
450450instance (FromRecord f) => FromObjectWithType'' f True where
@@ -452,8 +452,8 @@ instance (FromRecord f) => FromObjectWithType'' f True where
452452 {-# INLINE parseFromObjectWithType'' #-}
453453
454454instance (GFromJSON f) => FromObjectWithType'' f False where
455− parseFromObjectWithType'' opts valueFieldName = Tagged .
456− (gParseJSON opts <=< (.: pack valueFieldName))
455+ parseFromObjectWithType'' opts contentsFieldName = Tagged .
456+ (gParseJSON opts <=< (.: pack contentsFieldName))
457457 {-# INLINE parseFromObjectWithType'' #-}
458458
459459--------------------------------------------------------------------------------
Data/Aeson/Types/Internal.hs+10−10
@@ -272,8 +272,8 @@ data Options = Options
272272
273273-- | Specifies how to encode constructors of a sum datatype.
274274data SumEncoding =
275− ObjectWithType { typeFieldName :: String
276− , valueFieldName :: String
275+ ObjectWithType { typeFieldName :: String
276+ , contentsFieldName :: String
277277 }
278278 -- ^ A constructor will be encoded to an object with a field
279279 -- 'typeFieldName' which specifies the constructor name (modified
@@ -281,9 +281,9 @@ data SumEncoding =
281281 -- record the encoded record fields will be unpacked into this
282282 -- object. So make sure that your record doesn't have a field with
283283 -- the same name as the 'typeFieldName'. Otherwise the type gets
284− -- overwritten by that field. If the constructor is not a record
285− -- the encoded constructor content will be stored under the
286− -- 'valueFieldName' field.
284+ -- overwritten by that field! If the constructor is not a record
285+ -- the encoded constructor contents will be stored under the
286+ -- 'contentsFieldName' field.
287287 | ObjectWithSingleField
288288 -- ^ A constructor will be encoded to an object with a single
289289 -- field named after the constructor (modified by the
@@ -293,7 +293,7 @@ data SumEncoding =
293293 -- ^ A constructor will be encoded to a 2-element array where the
294294 -- first element is the name of the constructor (modified by the
295295 -- 'constructorNameModifier') and the second element the encoded
296− -- content of the constructor.
296+ -- contents of the constructor.
297297
298298-- | Default encoding 'Options':
299299--
@@ -319,12 +319,12 @@ defaultOptions = Options
319319--
320320-- @
321321-- defaultObjectWithType = 'ObjectWithType'
322−-- { 'typeFieldName' = \"type\"
323−-- , 'valueFieldName' = \"value\"
322+-- { 'typeFieldName' = \"type\"
323+-- , 'contentsFieldName' = \"contents\"
324324-- }
325325-- @
326326defaultObjectWithType :: SumEncoding
327327defaultObjectWithType = ObjectWithType
328− { typeFieldName = "type"
329− , valueFieldName = "value"
328+ { typeFieldName = "type"
329+ , contentsFieldName = "contents"
330330 }