on master help sign in
Renamed valueFieldName to contentsFieldName
00ebbbeBas van Dijk
Data/Aeson/TH.hs+5−5
@@ -234,10 +234,10 @@ encodeSum opts multiCons conName exp
234 case sumEncoding opts of
234 case sumEncoding opts of
235 TwoElemArray ->
235 TwoElemArray ->
236 [|Array|] `appE` ([|V.fromList|] `appE` listE [conStr opts conName, exp])
236 [|Array|] `appE` ([|V.fromList|] `appE` listE [conStr opts conName, exp])
237− ObjectWithType{typeFieldName, valueFieldName} ->
237+ ObjectWithType{typeFieldName, contentsFieldName} ->
238 [|object|] `appE` listE
238 [|object|] `appE` listE
239− [ infixApp [|T.pack typeFieldName|] [|(.=)|] (conStr opts conName)
239+ [ infixApp [|T.pack typeFieldName|] [|(.=)|] (conStr opts conName)
240− , infixApp [|T.pack valueFieldName|] [|(.=)|] exp
240+ , infixApp [|T.pack contentsFieldName|] [|(.=)|] exp
241 ]
241 ]
242 ObjectWithSingleField ->
242 ObjectWithSingleField ->
243 [|object|] `appE` listE
243 [|object|] `appE` listE
@@ -454,8 +454,8 @@ consFromJSON tName opts cons = do
454
454
455 mixedMatches =
455 mixedMatches =
456 case sumEncoding opts of
456 case sumEncoding opts of
457− ObjectWithType {typeFieldName, valueFieldName} ->
457+ ObjectWithType {typeFieldName, contentsFieldName} ->
458− parseObject $ parseObjectWithType typeFieldName valueFieldName
458+ parseObject $ parseObjectWithType typeFieldName contentsFieldName
459 ObjectWithSingleField ->
459 ObjectWithSingleField ->
460 parseObject $ parseObjectWithSingleField
460 parseObject $ parseObjectWithSingleField
461 TwoElemArray ->
461 TwoElemArray ->
Data/Aeson/Types/Generic.hs+19−19
@@ -110,7 +110,7 @@ nonAllNullarySumToJSON :: ( TwoElemArray f
110nonAllNullarySumToJSON opts =
110nonAllNullarySumToJSON opts =
111 case sumEncoding opts of
111 case sumEncoding opts of
112 ObjectWithType{..} -> object . objectWithType opts typeFieldName
112 ObjectWithType{..} -> object . objectWithType opts typeFieldName
113− valueFieldName
113+ contentsFieldName
114 ObjectWithSingleField -> Object . objectWithSingleField opts
114 ObjectWithSingleField -> Object . objectWithSingleField opts
115 TwoElemArray -> Array . twoElemArray opts
115 TwoElemArray -> Array . twoElemArray opts
116{-# INLINE nonAllNullarySumToJSON #-}
116{-# INLINE nonAllNullarySumToJSON #-}
@@ -122,20 +122,20 @@ class ObjectWithType f where
122
122
123instance ( ObjectWithType a
123instance ( ObjectWithType a
124 , ObjectWithType b ) => ObjectWithType (a :+: b) where
124 , ObjectWithType b ) => ObjectWithType (a :+: b) where
125− objectWithType opts typeFieldName valueFieldName (L1 x) =
125+ objectWithType opts typeFieldName contentsFieldName (L1 x) =
126− objectWithType opts typeFieldName valueFieldName x
126+ objectWithType opts typeFieldName contentsFieldName x
127− objectWithType opts typeFieldName valueFieldName (R1 x) =
127+ objectWithType opts typeFieldName contentsFieldName (R1 x) =
128− objectWithType opts typeFieldName valueFieldName x
128+ objectWithType opts typeFieldName contentsFieldName x
129 {-# INLINE objectWithType #-}
129 {-# INLINE objectWithType #-}
130
130
131instance ( IsRecord a isRecord
131instance ( IsRecord a isRecord
132 , ObjectWithType' a isRecord
132 , ObjectWithType' a isRecord
133 , Constructor c ) => ObjectWithType (C1 c a) where
133 , Constructor c ) => ObjectWithType (C1 c a) where
134− objectWithType opts typeFieldName valueFieldName =
134+ objectWithType opts typeFieldName contentsFieldName =
135 (pack typeFieldName .= constructorNameModifier opts
135 (pack typeFieldName .= constructorNameModifier opts
136 (conName (undefined :: t c a p)) :) .
136 (conName (undefined :: t c a p)) :) .
137 (unTagged :: Tagged isRecord [Pair] -> [Pair]) .
137 (unTagged :: Tagged isRecord [Pair] -> [Pair]) .
138− objectWithType' opts valueFieldName . unM1
138+ objectWithType' opts contentsFieldName . unM1
139 {-# INLINE objectWithType #-}
139 {-# INLINE objectWithType #-}
140
140
141class ObjectWithType' f isRecord where
141class ObjectWithType' f isRecord where
@@ -146,8 +146,8 @@ instance (RecordToPairs f) => ObjectWithType' f True where
146 {-# INLINE objectWithType' #-}
146 {-# INLINE objectWithType' #-}
147
147
148instance (GToJSON f) => ObjectWithType' f False where
148instance (GToJSON f) => ObjectWithType' f False where
149− objectWithType' opts valueFieldName =
149+ objectWithType' opts contentsFieldName =
150− Tagged . (:[]) . (pack valueFieldName .=) . gToJSON opts
150+ Tagged . (:[]) . (pack contentsFieldName .=) . gToJSON opts
151 {-# INLINE objectWithType' #-}
151 {-# INLINE objectWithType' #-}
152
152
153--------------------------------------------------------------------------------
153--------------------------------------------------------------------------------
@@ -387,7 +387,7 @@ parseNonAllNullarySum opts =
387 withObject "Object" $ \obj -> do
387 withObject "Object" $ \obj -> do
388 key <- obj .: pack typeFieldName
388 key <- obj .: pack typeFieldName
389 fromMaybe (notFound $ unpack key) $
389 fromMaybe (notFound $ unpack key) $
390− parseFromObjectWithType opts valueFieldName obj key
390+ parseFromObjectWithType opts contentsFieldName obj key
391
391
392 ObjectWithSingleField ->
392 ObjectWithSingleField ->
393 withObject "Object" $ \obj ->
393 withObject "Object" $ \obj ->
@@ -414,16 +414,16 @@ class FromObjectWithType f where
414
414
415instance (FromObjectWithType a, FromObjectWithType b) =>
415instance (FromObjectWithType a, FromObjectWithType b) =>
416 FromObjectWithType (a :+: b) where
416 FromObjectWithType (a :+: b) where
417− parseFromObjectWithType opts valueFieldName obj key =
417+ parseFromObjectWithType opts contentsFieldName obj key =
418− (fmap L1 <$> parseFromObjectWithType opts valueFieldName obj key) <|>
418+ (fmap L1 <$> parseFromObjectWithType opts contentsFieldName obj key) <|>
419− (fmap R1 <$> parseFromObjectWithType opts valueFieldName obj key)
419+ (fmap R1 <$> parseFromObjectWithType opts contentsFieldName obj key)
420 {-# INLINE parseFromObjectWithType #-}
420 {-# INLINE parseFromObjectWithType #-}
421
421
422instance ( FromObjectWithType' f
422instance ( FromObjectWithType' f
423 , Constructor c ) => FromObjectWithType (C1 c f) where
423 , Constructor c ) => FromObjectWithType (C1 c f) where
424− parseFromObjectWithType opts valueFieldName obj key
424+ parseFromObjectWithType opts contentsFieldName obj key
425 | key == name = Just $ M1 <$> parseFromObjectWithType'
425 | key == name = Just $ M1 <$> parseFromObjectWithType'
426− opts valueFieldName obj
426+ opts contentsFieldName obj
427 | otherwise = Nothing
427 | otherwise = Nothing
428 where
428 where
429 name = pack $ constructorNameModifier opts $
429 name = pack $ constructorNameModifier opts $
@@ -442,9 +442,9 @@ class FromObjectWithType'' f isRecord where
442instance ( IsRecord f isRecord
442instance ( IsRecord f isRecord
443 , FromObjectWithType'' f isRecord
443 , FromObjectWithType'' f isRecord
444 ) => FromObjectWithType' f where
444 ) => FromObjectWithType' f where
445− parseFromObjectWithType' opts valueFieldName =
445+ parseFromObjectWithType' opts contentsFieldName =
446 (unTagged :: Tagged isRecord (Parser (f a)) -> Parser (f a)) .
446 (unTagged :: Tagged isRecord (Parser (f a)) -> Parser (f a)) .
447− parseFromObjectWithType'' opts valueFieldName
447+ parseFromObjectWithType'' opts contentsFieldName
448 {-# INLINE parseFromObjectWithType' #-}
448 {-# INLINE parseFromObjectWithType' #-}
449
449
450instance (FromRecord f) => FromObjectWithType'' f True where
450instance (FromRecord f) => FromObjectWithType'' f True where
@@ -452,8 +452,8 @@ instance (FromRecord f) => FromObjectWithType'' f True where
452 {-# INLINE parseFromObjectWithType'' #-}
452 {-# INLINE parseFromObjectWithType'' #-}
453
453
454instance (GFromJSON f) => FromObjectWithType'' f False where
454instance (GFromJSON f) => FromObjectWithType'' f False where
455− parseFromObjectWithType'' opts valueFieldName = Tagged .
455+ parseFromObjectWithType'' opts contentsFieldName = Tagged .
456− (gParseJSON opts <=< (.: pack valueFieldName))
456+ (gParseJSON opts <=< (.: pack contentsFieldName))
457 {-# INLINE parseFromObjectWithType'' #-}
457 {-# INLINE parseFromObjectWithType'' #-}
458
458
459--------------------------------------------------------------------------------
459--------------------------------------------------------------------------------
Data/Aeson/Types/Internal.hs+10−10
@@ -272,8 +272,8 @@ data Options = Options
272
272
273-- | Specifies how to encode constructors of a sum datatype.
273-- | Specifies how to encode constructors of a sum datatype.
274data SumEncoding =
274data SumEncoding =
275− ObjectWithType { typeFieldName :: String
275+ ObjectWithType { typeFieldName :: String
276− , valueFieldName :: String
276+ , contentsFieldName :: String
277 }
277 }
278 -- ^ A constructor will be encoded to an object with a field
278 -- ^ A constructor will be encoded to an object with a field
279 -- 'typeFieldName' which specifies the constructor name (modified
279 -- 'typeFieldName' which specifies the constructor name (modified
@@ -281,9 +281,9 @@ data SumEncoding =
281 -- record the encoded record fields will be unpacked into this
281 -- record the encoded record fields will be unpacked into this
282 -- object. So make sure that your record doesn't have a field with
282 -- object. So make sure that your record doesn't have a field with
283 -- the same name as the 'typeFieldName'. Otherwise the type gets
283 -- the same name as the 'typeFieldName'. Otherwise the type gets
284− -- overwritten by that field. If the constructor is not a record
284+ -- overwritten by that field! If the constructor is not a record
285− -- the encoded constructor content will be stored under the
285+ -- the encoded constructor contents will be stored under the
286− -- 'valueFieldName' field.
286+ -- 'contentsFieldName' field.
287 | ObjectWithSingleField
287 | ObjectWithSingleField
288 -- ^ A constructor will be encoded to an object with a single
288 -- ^ A constructor will be encoded to an object with a single
289 -- field named after the constructor (modified by the
289 -- field named after the constructor (modified by the
@@ -293,7 +293,7 @@ data SumEncoding =
293 -- ^ A constructor will be encoded to a 2-element array where the
293 -- ^ A constructor will be encoded to a 2-element array where the
294 -- first element is the name of the constructor (modified by the
294 -- first element is the name of the constructor (modified by the
295 -- 'constructorNameModifier') and the second element the encoded
295 -- 'constructorNameModifier') and the second element the encoded
296− -- content of the constructor.
296+ -- contents of the constructor.
297
297
298-- | Default encoding 'Options':
298-- | Default encoding 'Options':
299--
299--
@@ -319,12 +319,12 @@ defaultOptions = Options
319--
319--
320-- @
320-- @
321-- defaultObjectWithType = 'ObjectWithType'
321-- defaultObjectWithType = 'ObjectWithType'
322−-- { 'typeFieldName' = \"type\"
322+-- { 'typeFieldName' = \"type\"
323−-- , 'valueFieldName' = \"value\"
323+-- , 'contentsFieldName' = \"contents\"
324-- }
324-- }
325-- @
325-- @
326defaultObjectWithType :: SumEncoding
326defaultObjectWithType :: SumEncoding
327defaultObjectWithType = ObjectWithType
327defaultObjectWithType = ObjectWithType
328− { typeFieldName = "type"
328+ { typeFieldName = "type"
329− , valueFieldName = "value"
329+ , contentsFieldName = "contents"
330 }
330 }