Commits

basvandijk committed 80fc106

Renamed nullaryToString to the more accurate allNullaryToStringTag

Comments (0)

Files changed (3)

     lam1E (varP value) $ caseE (varE value) matches
   where
     matches
-        | nullaryToString opts && all isNullary cons =
+        | allNullaryToStringTag opts && all isNullary cons =
               [ match (conP conName []) (normalB $ conStr opts conName) []
               | con <- cons
               , let conName = getConName con
 consFromJSON tName opts cons = do
   value <- newName "value"
   lam1E (varP value) $ caseE (varE value) $
-    if nullaryToString opts && all isNullary cons
+    if allNullaryToStringTag opts && all isNullary cons
     then allNullaryMatches
     else mixedMatches
 

Data/Aeson/Types/Generic.hs

 instance ( AllNullary (a :+: b) allNullary
          , SumToJSON  (a :+: b) allNullary ) => GToJSON (a :+: b) where
     -- If all constructors of a sum datatype are nullary and the
-    -- 'nullaryToString' option is set they are encoded to strings.
-    -- This distinction is made by 'sumToJSON':
+    -- 'allNullaryToStringTag' option is set they are encoded to
+    -- strings.  This distinction is made by 'sumToJSON':
     gToJSON opts = (unTagged :: Tagged allNullary Value -> Value)
                  . sumToJSON opts
     {-# INLINE gToJSON #-}
          , ObjectWithSingleField f
          , TwoElemArray          f ) => SumToJSON f True where
     sumToJSON opts
-        | nullaryToString opts = Tagged . String . pack
-                               . constructorTagModifier opts . getConName
+        | allNullaryToStringTag opts = Tagged . String . pack
+                                     . constructorTagModifier opts . getConName
         | otherwise = Tagged . nonAllNullarySumToJSON opts
     {-# INLINE sumToJSON #-}
 
 instance ( AllNullary (a :+: b) allNullary
          , ParseSum   (a :+: b) allNullary ) => GFromJSON   (a :+: b) where
     -- If all constructors of a sum datatype are nullary and the
-    -- 'nullaryToString' option is set they are expected to be encoded as
-    -- strings.  This distinction is made by 'parseSum':
+    -- 'allNullaryToStringTag' option is set they are expected to be
+    -- encoded as strings.  This distinction is made by 'parseSum':
     gParseJSON opts = (unTagged :: Tagged allNullary (Parser ((a :+: b) d)) ->
                                                      (Parser ((a :+: b) d)))
                     . parseSum opts
          , FromPair         (a :+: b)
          , FromTaggedObject (a :+: b) ) => ParseSum (a :+: b) True where
     parseSum opts
-        | nullaryToString opts = Tagged . parseAllNullarySum    opts
-        | otherwise            = Tagged . parseNonAllNullarySum opts
+        | allNullaryToStringTag opts = Tagged . parseAllNullarySum    opts
+        | otherwise                  = Tagged . parseNonAllNullarySum opts
     {-# INLINE parseSum #-}
 
 instance ( FromPair         (a :+: b)

Data/Aeson/Types/Internal.hs

     , constructorTagModifier :: String -> String
       -- ^ Function applied to constructor tags which could be handy
       -- for lower-casing them for example.
-    , nullaryToString :: Bool
+    , allNullaryToStringTag :: Bool
       -- ^ If 'True' the constructors of a datatype, with /all/
       -- nullary constructors, will be encoded to just a string with
       -- the constructor tag. If 'False' the encoding will always
 -- 'Options'
 -- { 'fieldLabelModifier'      = id
 -- , 'constructorTagModifier'  = id
--- , 'nullaryToString'         = True
+-- , 'allNullaryToStringTag'   = True
 -- , 'omitNothingFields'       = False
 -- , 'sumEncoding'             = 'defaultTaggedObject'
 -- }
 defaultOptions = Options
                  { fieldLabelModifier      = id
                  , constructorTagModifier  = id
-                 , nullaryToString         = True
+                 , allNullaryToStringTag   = True
                  , omitNothingFields       = False
                  , sumEncoding             = defaultTaggedObject
                  }
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.