Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bos committed Mar 14, 2011
2 parents 37f9b57 + f631eaf commit 44c56a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions .hgtags
@@ -1,3 +1,4 @@
05d9437b2280648ae25ac170697ec1c48eda7af0 0.1.0.0
f4cf6abd5a81affb08c6563d51e38ac4f8451217 0.2.0.0
fe4084e5615941d9822834239e4c32a036291327 0.3.0.0
75142422b9b377b552b7763ebbab4fe6d1f033b6 0.3.1.0
17 changes: 16 additions & 1 deletion Data/Aeson/Generic.hs
Expand Up @@ -26,6 +26,7 @@ import Data.Aeson.Functions
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)
Expand Down Expand Up @@ -159,7 +160,7 @@ parseJSON j = parseJSON_generic j
`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)
Expand Down Expand Up @@ -214,6 +215,20 @@ parseJSON j = parseJSON_generic j
"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 ""]
Expand Down
2 changes: 1 addition & 1 deletion aeson.cabal
@@ -1,5 +1,5 @@
name: aeson
version: 0.3.0.1
version: 0.3.1.0
license: BSD3
license-file: LICENSE
category: Text, Web, JSON
Expand Down

0 comments on commit 44c56a6

Please sign in to comment.