on master help sign in
Renamed nullaryToString to the more accurate allNullaryToStringTag
commit4d4525806d7dbc90b32a60ce2913874863fffb9e authorBas van Dijk <v.dijk.bas@gmail.com> dateTue 23 Apr 2013, 01:42 (13 years ago) parent0ec4f5d
3 files changed+13−13
Data/Aeson/TH.hs+2−2 Data/Aeson/Types/Generic.hs+8−8 Data/Aeson/Types/Internal.hs+3−3
Data/Aeson/TH.hs+2−2
@@ -207,7 +207,7 @@ consToJSON opts cons = do
207207 lam1E (varP value) $ caseE (varE value) matches
208208 where
209209 matches
210− | nullaryToString opts && all isNullary cons =
210+ | allNullaryToStringTag opts && all isNullary cons =
211211 [ match (conP conName []) (normalB $ conStr opts conName) []
212212 | con <- cons
213213 , let conName = getConName con
@@ -414,7 +414,7 @@ consFromJSON tName opts [con] = do
414414consFromJSON tName opts cons = do
415415 value <- newName "value"
416416 lam1E (varP value) $ caseE (varE value) $
417− if nullaryToString opts && all isNullary cons
417+ if allNullaryToStringTag opts && all isNullary cons
418418 then allNullaryMatches
419419 else mixedMatches
420420
Data/Aeson/Types/Generic.hs+8−8
@@ -76,8 +76,8 @@ instance ( WriteProduct a, WriteProduct b
7676instance ( AllNullary (a :+: b) allNullary
7777 , SumToJSON (a :+: b) allNullary ) => GToJSON (a :+: b) where
7878 -- If all constructors of a sum datatype are nullary and the
79− -- 'nullaryToString' option is set they are encoded to strings.
80− -- This distinction is made by 'sumToJSON':
79+ -- 'allNullaryToStringTag' option is set they are encoded to
80+ -- strings. This distinction is made by 'sumToJSON':
8181 gToJSON opts = (unTagged :: Tagged allNullary Value -> Value)
8282 . sumToJSON opts
8383 {-# INLINE gToJSON #-}
@@ -92,8 +92,8 @@ instance ( GetConName f
9292 , ObjectWithSingleField f
9393 , TwoElemArray f ) => SumToJSON f True where
9494 sumToJSON opts
95− | nullaryToString opts = Tagged . String . pack
96− . constructorTagModifier opts . getConName
95+ | allNullaryToStringTag opts = Tagged . String . pack
96+ . constructorTagModifier opts . getConName
9797 | otherwise = Tagged . nonAllNullarySumToJSON opts
9898 {-# INLINE sumToJSON #-}
9999
@@ -327,8 +327,8 @@ instance ( FromProduct a, FromProduct b
327327instance ( AllNullary (a :+: b) allNullary
328328 , ParseSum (a :+: b) allNullary ) => GFromJSON (a :+: b) where
329329 -- If all constructors of a sum datatype are nullary and the
330− -- 'nullaryToString' option is set they are expected to be encoded as
331− -- strings. This distinction is made by 'parseSum':
330+ -- 'allNullaryToStringTag' option is set they are expected to be
331+ -- encoded as strings. This distinction is made by 'parseSum':
332332 gParseJSON opts = (unTagged :: Tagged allNullary (Parser ((a :+: b) d)) ->
333333 (Parser ((a :+: b) d)))
334334 . parseSum opts
@@ -343,8 +343,8 @@ instance ( SumFromString (a :+: b)
343343 , FromPair (a :+: b)
344344 , FromTaggedObject (a :+: b) ) => ParseSum (a :+: b) True where
345345 parseSum opts
346− | nullaryToString opts = Tagged . parseAllNullarySum opts
347− | otherwise = Tagged . parseNonAllNullarySum opts
346+ | allNullaryToStringTag opts = Tagged . parseAllNullarySum opts
347+ | otherwise = Tagged . parseNonAllNullarySum opts
348348 {-# INLINE parseSum #-}
349349
350350instance ( FromPair (a :+: b)
Data/Aeson/Types/Internal.hs+3−3
@@ -257,7 +257,7 @@ data Options = Options
257257 , constructorTagModifier :: String -> String
258258 -- ^ Function applied to constructor tags which could be handy
259259 -- for lower-casing them for example.
260− , nullaryToString :: Bool
260+ , allNullaryToStringTag :: Bool
261261 -- ^ If 'True' the constructors of a datatype, with /all/
262262 -- nullary constructors, will be encoded to just a string with
263263 -- the constructor tag. If 'False' the encoding will always
@@ -301,7 +301,7 @@ data SumEncoding =
301301-- 'Options'
302302-- { 'fieldLabelModifier' = id
303303-- , 'constructorTagModifier' = id
304−-- , 'nullaryToString' = True
304+-- , 'allNullaryToStringTag' = True
305305-- , 'omitNothingFields' = False
306306-- , 'sumEncoding' = 'defaultTaggedObject'
307307-- }
@@ -310,7 +310,7 @@ defaultOptions :: Options
310310defaultOptions = Options
311311 { fieldLabelModifier = id
312312 , constructorTagModifier = id
313− , nullaryToString = True
313+ , allNullaryToStringTag = True
314314 , omitNothingFields = False
315315 , sumEncoding = defaultTaggedObject
316316 }