Bryan O'Sullivan avatar Bryan O'Sullivan committed 6b6f86d Merge

Merge

Comments (0)

Files changed (3)

 05d9437b2280648ae25ac170697ec1c48eda7af0 0.1.0.0
 f4cf6abd5a81affb08c6563d51e38ac4f8451217 0.2.0.0
 fe4084e5615941d9822834239e4c32a036291327 0.3.0.0
+75142422b9b377b552b7763ebbab4fe6d1f033b6 0.3.1.0

Data/Aeson/Generic.hs

 import Data.Aeson.Types hiding (FromJSON(..), ToJSON(..), fromJSON)
 import Data.Attoparsec.Number (Number)
 import Data.Generics
+import Data.Hashable (Hashable)
 import Data.Int (Int8, Int16, Int32, Int64)
 import Data.IntSet (IntSet)
 import Data.Maybe (fromJust)
              `ext1R` list
              `ext1R` vector
              `ext2R'` mapAny
-             -- Don't know how to support parsing HashMaps :-(
+             `ext2R'` hashMapAny
              -- Use the standard encoding for all base types.
              `extR` (value :: F Integer)
              `extR` (value :: F Int)
                                       "mapAny -- should never happen"
             tyrep = typeOf (undefined :: f)
             remap f = fromJust . cast . f
+    hashMapAny :: forall e f. (Data e, Data f) => Parser (H.HashMap f e)
+    hashMapAny
+        | tyrep == typeOf ""       = process DT.unpack
+        | tyrep == typeOf LT.empty = process LT.fromStrict
+        | tyrep == typeOf DT.empty = process id
+        | otherwise = myFail
+      where
+        process f = maybe myFail return . cast =<< parseWith f
+        parseWith :: (Eq c, Hashable c) => (Text -> c) -> Parser (H.HashMap c e)
+        parseWith f = case j of
+                        Object js -> H.fromList . map (first f) . Map.toList <$>
+                                     T.mapM parseJSON js
+                        _          -> myFail
+        tyrep = typeOf (undefined :: f)
     myFail = modFail "parseJSON" $ "bad data: " ++ show j
     stringyTypes = [typeOf LT.empty, typeOf DT.empty, typeOf B.empty, 
                     typeOf L.empty, typeOf ""]
 name:            aeson
-version:         0.3.0.1
+version:         0.3.1.0
 license:         BSD3
 license-file:    LICENSE
 category:        Text, Web, JSON
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.