json-autotype 1.0.11 → 1.0.12
raw patch · 4 files changed
+25/−8 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/Aeson/AutoType/CodeGen.hs +5/−0
- Data/Aeson/AutoType/Format.hs +13/−5
- changelog.md +5/−1
- json-autotype.cabal +2/−2
Data/Aeson/AutoType/CodeGen.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} -- | Wrappers for generating prologue and epilogue code in Haskell. module Data.Aeson.AutoType.CodeGen(@@ -45,7 +46,11 @@ ,"import Control.Applicative" ,"import Data.Aeson.AutoType.Alternative" ,"import Data.Aeson(decode, Value(..), FromJSON(..), ToJSON(..),"+#if MIN_VERSION_aeson(0,11,0)+ ," pairs,"+#endif ," (.:), (.:?), (.=), object)"+ ,"import Data.Monoid" ,"import Data.Text (Text)" ,"import GHC.Generics" ,""
Data/Aeson/AutoType/Format.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGuaGE ScopedTypeVariables #-} {-# LANGUAGE ViewPatterns #-}@@ -18,6 +19,7 @@ import Control.Monad (forM) import Control.Exception(assert) import qualified Data.HashMap.Strict as Map+import Data.Monoid import qualified Data.Set as Set import qualified Data.Text as Text import Data.Text (Text)@@ -98,14 +100,20 @@ makeToJSON :: Text -> [MappedKey] -> Text makeToJSON identifier contents = Text.unlines [- Text.concat ["instance ToJSON ", identifier, " where"],- Text.concat [" toJSON (", identifier, " {", wildcard, "}) = object [", inner, "]"]+ Text.concat ["instance ToJSON ", identifier, " where"]+ , Text.concat [" toJSON (", identifier, " {", wildcard, "}) = object [", inner ", ", "]"]+#if MIN_VERSION_aeson(0,11,0)+ , maybeToEncoding+#endif ] where+ maybeToEncoding | null contents = ""+ | otherwise =+ Text.concat [" toEncoding (", identifier, " {", wildcard, "}) = pairs (", inner "<>", ")"] wildcard | null contents = "" | otherwise = ".."- inner = ", " `Text.intercalate`- map putValue contents+ inner separator = separator `Text.intercalate`+ map putValue contents putValue (jsonId, haskellId, _typeText, _nullable) = Text.unwords [escapeText jsonId, ".=", haskellId] escapeText = Text.pack . show . Text.unpack -- Contents example for wrapToJSON@@ -165,7 +173,7 @@ -- the separate declarations on which this one is dependent. formatType :: Type -> DeclM Text formatType TString = return "Text"-formatType TNum = return "Int"+formatType TNum = return "Double" formatType TBool = return "Bool" formatType (TLabel l) = return $ normalizeTypeName l formatType (TUnion u) = wrap <$> case length nonNull of
changelog.md view
@@ -1,9 +1,13 @@ Changelog =========+ 1.0.12 Mar 2016++ * Fixed issue #8 - misrepresenting Double as Int.+ * Fixed issue #9 - efficient formatting with new Aeson-0.10 builder (toEncoding.)+ 1.0.11 Mar 2016 * Updated to GHC 8.0- 1.0.10 Sep 2015
json-autotype.cabal view
@@ -1,6 +1,6 @@ -- Build information for the package. name: json-autotype-version: 1.0.11+version: 1.0.12 synopsis: Automatic type declaration for JSON input data description: Generates datatype declarations with Aeson's "FromJSON" instances from a set of example ".json" files.@@ -34,7 +34,7 @@ extra-source-files: README.md changelog.md cabal-version: >=1.10 bug-reports: https://github.com/mgajda/json-autotype/issues-tested-with: GHC==7.8.4,GHC==7.10.1,GHC==7.6.3+tested-with: GHC==7.8.4,GHC==7.10.3,GHC==7.6.3 source-repository head type: git