packages feed

RJson 0.1 → 0.2

raw patch · 2 files changed

+16/−9 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Text.RJson: instance [overlap ok] (Data FromJsonD t) => FromJson t
+ Text.RJson: instance [overlap ok] (Data FromJsonD t, Data TranslateFieldD t) => FromJson t
+ Text.RJson: instance [overlap ok] (Data ctx Int, Sat (ctx Test2), Sat (ctx Int)) => Data ctx Test2
+ Text.RJson: instance [overlap ok] (Sat (ctx Test)) => Data ctx Test
+ Text.RJson: instance [overlap ok] Show Test
+ Text.RJson: instance [overlap ok] Show Test2
+ Text.RJson: instance [overlap ok] Typeable Test
+ Text.RJson: instance [overlap ok] Typeable Test2
- Text.RJson: genericFromJson :: (Data FromJsonD a) => a -> JsonData -> Either String a
+ Text.RJson: genericFromJson :: (Data FromJsonD a, Data TranslateFieldD a) => a -> JsonData -> Either String a

Files

RJson.cabal view
@@ -1,5 +1,5 @@ Name:          RJson-Version:       0.1+Version:       0.2 Cabal-Version: >= 1.2 License:       BSD3 License-File:  LICENSE
Text/RJson.hs view
@@ -1,3 +1,5 @@+{-# OPTIONS_GHC -XFlexibleInstances -XOverlappingInstances -XMultiParamTypeClasses -XFlexibleContexts -XUndecidableInstances -XTemplateHaskell #-}+ module Text.RJson (TranslateField,                    TranslateFieldD,                    translateField,@@ -265,11 +267,8 @@ genericToJson x         | isAlgType (dataTypeOf toJsonProxy x) =             case (map (translateFieldD' dict x) (filter (not . (excludeD dict x)) (getFields x))) of-              [] -> JDArray $-                      arrayPrependD dict x ++-                      (JDString (dataTypeName (dataTypeOf toJsonProxy x)) :-                       (gmapQ toJsonProxy (toJsonD dict) x)) ++-                      arrayAppendD dict x+              [] -> case gmapQ toJsonProxy (toJsonD dict) x of+                      l  -> JDArray $ (arrayPrependD dict x) ++ l ++ (arrayAppendD dict x)               fs -> JDObject (M.fromList (objectExtrasD dict x ++ (zip fs (gmapQ toJsonProxy (toJsonD dict) x))))         | True =             error ("Unable to serialize the primitive type '" ++ typename x ++ "'")@@ -533,8 +532,7 @@               Left e  -> throwError e               Right x -> return x)) -genericFromJson :: Data FromJsonD a => a -> JsonData -> Either String a-genericFromJson _     (JDArray []) = Left "Bad fromJson conversion: JSON array must contain at least one element"+genericFromJson :: (Data FromJsonD a, Data TranslateFieldD a) => a -> JsonData -> Either String a genericFromJson dummy (JDArray l) =     case datarep (dataTypeOf fromJsonProxy dummy) of       AlgRep (c:_) ->@@ -549,8 +547,9 @@             fs -> evalState (runErrorT (gmapM fromJsonProxy (m2 (objectDefaultsD dict dummy)) (fromConstr fromJsonProxy c))) (m, fs)       AlgRep _     -> Left "Bad fromJson conversion: Type with no constructors!"       _            -> Left "Bad fromJson conversion: Non-algebraic datatype given to 'genericFromJson'"+genericFromJson _ _ = Left "Bad fromJson conversion: Expecting JSON object or array"           -instance (Data FromJsonD t) => FromJson t where+instance (Data FromJsonD t, Data TranslateFieldD t) => FromJson t where     fromJson = genericFromJson  @@ -748,3 +747,11 @@ -- | Converts a value to an ASCII-only JSON String. toJsonString :: ToJson a => a -> String toJsonString = show . toJson++data Test = Foo | Bar deriving Show+$(derive[''Test])+data Test2 = Test2 Int Int deriving Show+$(derive[''Test2])++trans :: (Data FromJsonD a) => a -> Int+trans _ = 7