on master help sign in
Merge
382fb66Bryan O'Sullivan
@@ -1,3 +1,4 @@
105d9437b2280648ae25ac170697ec1c48eda7af0 0.1.0.0
105d9437b2280648ae25ac170697ec1c48eda7af0 0.1.0.0
2f4cf6abd5a81affb08c6563d51e38ac4f8451217 0.2.0.0
2f4cf6abd5a81affb08c6563d51e38ac4f8451217 0.2.0.0
3fe4084e5615941d9822834239e4c32a036291327 0.3.0.0
3fe4084e5615941d9822834239e4c32a036291327 0.3.0.0
4+75142422b9b377b552b7763ebbab4fe6d1f033b6 0.3.1.0
Data/Aeson/Generic.hs+16−1
@@ -26,6 +26,7 @@ import Data.Aeson.Functions
26import Data.Aeson.Types hiding (FromJSON(..), ToJSON(..), fromJSON)
26import Data.Aeson.Types hiding (FromJSON(..), ToJSON(..), fromJSON)
27import Data.Attoparsec.Number (Number)
27import Data.Attoparsec.Number (Number)
28import Data.Generics
28import Data.Generics
29+import Data.Hashable (Hashable)
29import Data.Int (Int8, Int16, Int32, Int64)
30import Data.Int (Int8, Int16, Int32, Int64)
30import Data.IntSet (IntSet)
31import Data.IntSet (IntSet)
31import Data.Maybe (fromJust)
32import Data.Maybe (fromJust)
@@ -159,7 +160,7 @@ parseJSON j = parseJSON_generic j
159 `ext1R` list
160 `ext1R` list
160 `ext1R` vector
161 `ext1R` vector
161 `ext2R'` mapAny
162 `ext2R'` mapAny
162− -- Don't know how to support parsing HashMaps :-(
163+ `ext2R'` hashMapAny
163 -- Use the standard encoding for all base types.
164 -- Use the standard encoding for all base types.
164 `extR` (value :: F Integer)
165 `extR` (value :: F Integer)
165 `extR` (value :: F Int)
166 `extR` (value :: F Int)
@@ -214,6 +215,20 @@ parseJSON j = parseJSON_generic j
214 "mapAny -- should never happen"
215 "mapAny -- should never happen"
215 tyrep = typeOf (undefined :: f)
216 tyrep = typeOf (undefined :: f)
216 remap f = fromJust . cast . f
217 remap f = fromJust . cast . f
218+ hashMapAny :: forall e f. (Data e, Data f) => Parser (H.HashMap f e)
219+ hashMapAny
220+ | tyrep == typeOf "" = process DT.unpack
221+ | tyrep == typeOf LT.empty = process LT.fromStrict
222+ | tyrep == typeOf DT.empty = process id
223+ | otherwise = myFail
224+ where
225+ process f = maybe myFail return . cast =<< parseWith f
226+ parseWith :: (Eq c, Hashable c) => (Text -> c) -> Parser (H.HashMap c e)
227+ parseWith f = case j of
228+ Object js -> H.fromList . map (first f) . Map.toList <$>
229+ T.mapM parseJSON js
230+ _ -> myFail
231+ tyrep = typeOf (undefined :: f)
217 myFail = modFail "parseJSON" $ "bad data: " ++ show j
232 myFail = modFail "parseJSON" $ "bad data: " ++ show j
218 stringyTypes = [typeOf LT.empty, typeOf DT.empty, typeOf B.empty,
233 stringyTypes = [typeOf LT.empty, typeOf DT.empty, typeOf B.empty,
219 typeOf L.empty, typeOf ""]
234 typeOf L.empty, typeOf ""]
aeson.cabal+1−1
@@ -1,5 +1,5 @@
1name: aeson
1name: aeson
2−version: 0.3.0.1
2+version: 0.3.1.0
3license: BSD3
3license: BSD3
4license-file: LICENSE
4license-file: LICENSE
5category: Text, Web, JSON
5category: Text, Web, JSON