Skip to content
Browse files

Get rid of "_"-prefixed field name mangling.

This fixes gh-53.
  • Loading branch information...
1 parent 017fdb4 commit 26ad412e4ac1da44304d95cd356f6a3fcf8a7ccb @bos committed
Showing with 4 additions and 13 deletions.
  1. +4 −10 Data/Aeson/Generic.hs
  2. +0 −3 tests/Properties.hs
View
14 Data/Aeson/Generic.hs
@@ -145,12 +145,6 @@ toJSON = toJSON_generic
where tyrep = typeOf . head . H.keys $ m
remap f = Object . mapKeyVal (f . fromJust . cast) toJSON $ m
--- Skip leading '_' in field name so we can use keywords
--- etc. as field names.
-mungeField :: String -> Text
-mungeField ('_':cs) = pack cs
-mungeField cs = pack cs
-
toJSON_generic :: (Data a) => a -> Value
toJSON_generic = generic
where
@@ -183,7 +177,7 @@ toJSON_generic = generic
encodeArgs c = encodeArgs' (constrFields c)
encodeArgs' [] [j] = j
encodeArgs' [] js = Array . V.fromList $ js
- encodeArgs' ns js = object $ zip (map mungeField ns) js
+ encodeArgs' ns js = object $ zip (map pack ns) js
fromJSON :: (Data a) => Value -> Result a
@@ -318,9 +312,9 @@ parseJSON_generic j = generic
(j':js') -> do put js'; lift $ parseJSON j'
-- Select the named fields from a JSON object.
- selectFields fjs = mapM sel
- where sel f = maybe (modFail "parseJSON" $ "field does not exist " ++
- f) return $ H.lookup (mungeField f) fjs
+ selectFields fjs = mapM $ \f ->
+ maybe (modFail "parseJSON" $ "field does not exist " ++ f) return $
+ H.lookup (pack f) fjs
-- Count how many arguments a constructor has. The value x is
-- used to determine what type the constructor returns.
View
3 tests/Properties.hs
@@ -100,9 +100,6 @@ instance (Ord k, Arbitrary k, Arbitrary v) => Arbitrary (Map.Map k v) where
instance Arbitrary Foo where
arbitrary = liftM4 Foo arbitrary arbitrary arbitrary arbitrary
-{-
- Test for Data.Aeson.Generic handling '_' names
--}
data UFoo = UFoo {
_UFooInt :: Int
, uFooInt :: Int

0 comments on commit 26ad412

Please sign in to comment.
Something went wrong with that request. Please try again.