HsYAML-aeson 0.2.0.0 → 0.2.0.1
raw patch · 5 files changed
+122/−8 lines, 5 filesdep +HsYAML-aesondep +directorydep ~HsYAMLdep ~aesondep ~basenew-component:exe:yaml-testnew-uploaderPVP ok
version bump matches the API change (PVP)
Dependencies added: HsYAML-aeson, directory
Dependency ranges changed: HsYAML, aeson, base, bytestring, containers, mtl, text, vector
API changes (from Hackage documentation)
Files
- CHANGELOG.md +5/−0
- HsYAML-aeson.cabal +38/−5
- LICENSE.GPLv2 +0/−1
- src-test/Main.hs +60/−0
- src/Data/YAML/Aeson.hs +19/−2
CHANGELOG.md view
@@ -1,5 +1,10 @@ See also http://pvp.haskell.org/faq +## 0.2.0.1++* Allow `aeson-2.0` and `bytestring-0.11`.+* Build tested with GHC 7.4 -- 9.0.+ ## 0.2.0.0 This release incorporates the work from [Vijay Tadikamalla's GSOC 2019 Project](https://vijayphoenix.github.io/blog/gsoc-the-conclusion/).
HsYAML-aeson.cabal view
@@ -1,10 +1,10 @@ cabal-version: 2.2 name: HsYAML-aeson-version: 0.2.0.0+version: 0.2.0.1 license: GPL-2.0-or-later license-file: LICENSE.GPLv2 author: Herbert Valerio Riedel-maintainer: hvr@gnu.org+maintainer: hvr@gnu.org, Andreas Abel copyright: 2018-2019 Herbert Valerio Riedel category: Text, Codec, Web, JSON, YAML synopsis: JSON to YAML Adapter@@ -20,6 +20,19 @@ convenience by reusing [aeson](https://hackage.haskell.org/package/aeson)'s 'FromJSON' instances for decoding the YAML data into native Haskell data types. +tested-with:+ GHC == 9.0.1+ GHC == 8.10.7+ GHC == 8.8.4+ GHC == 8.6.5+ GHC == 8.4.4+ GHC == 8.2.2+ GHC == 8.0.2+ GHC == 7.10.3+ GHC == 7.8.4+ GHC == 7.6.3+ GHC == 7.4.2+ extra-source-files: CHANGELOG.md @@ -27,13 +40,18 @@ type: git location: https://github.com/hvr/HsYAML-aeson.git +flag exe+ description: Enable @exe:yaml-test@ component+ manual: True+ default: False+ library exposed-modules: Data.YAML.Aeson build-depends: , HsYAML ^>= 0.2.0- , aeson ^>= 1.4.0.0- , base >= 4.5 && < 4.14- , bytestring ^>= 0.9.2.1 || ^>= 0.10.0.2+ , aeson ^>= 1.4.0.0 || ^>= 1.5.0.0 || ^>= 2.0.0.0+ , base >= 4.5 && < 4.17+ , bytestring ^>= 0.9.2.1 || ^>= 0.10.0.2 || ^>= 0.11.0.0 , containers >=0.4.2 && <0.7 , mtl ^>= 2.2.1 , scientific ^>= 0.3.6.2@@ -45,3 +63,18 @@ default-language: Haskell2010 other-extensions: RecordWildCards Trustworthy ghc-options: -Wall++executable yaml-test+ hs-source-dirs: src-test+ main-is: Main.hs+ default-language: Haskell2010++ if flag(exe)+ build-depends: HsYAML+ , HsYAML-aeson+ , base+ , aeson+ , bytestring+ , directory >= 1.2 && < 1.4+ else+ buildable: False
LICENSE.GPLv2 view
@@ -1,7 +1,6 @@ GNU GENERAL PUBLIC LICENSE Version 2, June 1991 - Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies
+ src-test/Main.hs view
@@ -0,0 +1,60 @@+-- |+-- Copyright: © Herbert Valerio Riedel 2018+-- SPDX-License-Identifier: GPL-2.0-or-later+--+module Main where++import qualified Data.Aeson as J+import qualified Data.ByteString.Char8 as BS+import qualified Data.ByteString.Lazy.Char8 as BS.L+import System.Environment+import System.Exit+import System.IO+import Data.YAML+import Data.YAML.Aeson++main :: IO ()+main = do+ args <- getArgs++ case args of+ ("yaml2json":args')+ | null args' -> cmdYaml2Json+ | otherwise -> do+ hPutStrLn stderr "unexpected arguments passed to yaml2json sub-command"+ exitFailure++ ("json2yaml":args')+ | null args' -> cmdJson2Yaml+ | otherwise -> do+ hPutStrLn stderr "unexpected arguments passed to json2yaml sub-command"+ exitFailure++ _ -> do+ hPutStrLn stderr "usage: yaml-test <command> [<args>]"+ hPutStrLn stderr ""+ hPutStrLn stderr "Commands:"+ hPutStrLn stderr ""+ hPutStrLn stderr " yaml2json reads YAML stream from STDIN and dumps JSON to STDOUT"+ hPutStrLn stderr " json2yaml reads JSON stream from STDIN and dumps YAML to STDOUT"+ exitFailure+++cmdYaml2Json :: IO ()+cmdYaml2Json = do+ inYamlDat <- BS.L.getContents+ case decodeValue inYamlDat of+ Left (loc, err) -> do+ hPutStrLn stderr (prettyPosWithSource loc inYamlDat " error" ++ err)+ exitFailure+ Right x -> (BS.L.putStr . J.encode) x+++cmdJson2Yaml :: IO ()+cmdJson2Yaml = do+ inJsonDat <- BS.L.getContents+ case J.eitherDecode inJsonDat of+ Left e -> do+ hPutStrLn stderr e+ exitFailure+ Right x -> (BS.L.putStr . encodeValue . return) x
src/Data/YAML/Aeson.hs view
@@ -39,6 +39,10 @@ import Control.Applicative as Ap import Control.Monad.Identity (runIdentity) import Data.Aeson as J+#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.Key as AK+import qualified Data.Aeson.KeyMap as AKM+#endif import qualified Data.Aeson.Types as J import qualified Data.ByteString as BS import qualified Data.ByteString.Lazy as BS.L@@ -164,8 +168,13 @@ mkPair :: Pos -> (J.Value,J.Value) -> Either (Pos, String) J.Pair mkPair pos (k, v) = case keyconv k of- Right k' -> Right (k', v)+ Right k' -> Right (fT k', v) Left s -> Left (pos, s)+#if MIN_VERSION_aeson(2,0,0)+ fT = AK.fromText+#else+ fT = id +#endif mkArr :: [J.Value] -> Either (Pos, String) J.Value mkArr xs = Right $! J.Array $! V.fromList xs@@ -207,7 +216,15 @@ Right d -> toYAML d Left int -> toYAML int toYAML (J.Array a) = toYAML (V.toList a)- toYAML (J.Object o) = toYAML (Map.fromList (HM.toList o))+ toYAML (J.Object o) = toYAML (Map.fromList (fromObject o))+ where+#if MIN_VERSION_aeson(2,0,0)+ fromObject = fmap (\(k, v) -> (AK.toText k, v)) . AKM.toList+#else+ fromObject = HM.toList+#endif++ -- | Serialize JSON Value using the YAML 1.2 Core schema to a lazy 'BS.L.ByteString'. --