validity-aeson 0.2.0.4 → 0.2.0.5
raw patch · 4 files changed
+25/−16 lines, 4 filesdep ~aesonsetup-changed
Dependency ranges changed: aeson
Files
- LICENSE +1/−1
- Setup.hs +0/−3
- src/Data/Validity/Aeson.hs +21/−7
- validity-aeson.cabal +3/−5
LICENSE view
@@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016-2020 Tom Sydney Kerckhove+Copyright (c) 2016-2021 Tom Sydney Kerckhove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
− Setup.hs
@@ -1,3 +0,0 @@-import Distribution.Simple--main = defaultMain
src/Data/Validity/Aeson.hs view
@@ -1,8 +1,14 @@+{-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Data.Validity.Aeson where import Data.Aeson+#if MIN_VERSION_aeson(2,0,0)+import Data.Aeson.KeyMap (KeyMap)+import qualified Data.Aeson.KeyMap as KM+import qualified Data.Aeson.Key as K+#endif import Data.Aeson.Types import Data.Validity import Data.Validity.HashMap ()@@ -10,14 +16,22 @@ import Data.Validity.Text () import Data.Validity.Vector () +#if MIN_VERSION_aeson(2,0,0)+instance Validity v => Validity (KeyMap v) where+ validate m = annotate (KM.toHashMap m) "KeyMap"++instance Validity Key where+ validate k = annotate (K.toText k) "Key"+#endif+ -- | A 'Value' is valid if the recursive components are valid. instance Validity Value where- validate (Object o) = annotate o "Object"- validate (Array a) = annotate a "Array"- validate (String t) = annotate t "String"- validate (Number s) = annotate s "Number"- validate (Bool b) = annotate b "Bool"- validate Null = valid+ validate (Object o) = annotate o "Object"+ validate (Array a) = annotate a "Array"+ validate (String t) = annotate t "String"+ validate (Number s) = annotate s "Number"+ validate (Bool b) = annotate b "Bool"+ validate Null = valid -- | Modify a parser to fail on invalid results. parseJSONValid :: Validity a => Parser a -> Parser a@@ -31,7 +45,7 @@ -- -- Easy to use with the `withX` helper functions: ----- > parseJSON = parseJSONValidwith . withObject "MyThing" $ \o ->+-- > parseJSON = parseJSONValidWith . withObject "MyThing" $ \o -> -- > MyThing <$> ... parseJSONValidWith :: Validity a => (value -> Parser a) -> (value -> Parser a) parseJSONValidWith func v = parseJSONValid $ func v
validity-aeson.cabal view
@@ -1,20 +1,18 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.34.7. -- -- see: https://github.com/sol/hpack------ hash: 2c831f84f06bf64abf7f2d9df6acbdbef462d918f20615688f51d89683e57cae name: validity-aeson-version: 0.2.0.4+version: 0.2.0.5 synopsis: Validity instances for aeson category: Validity homepage: https://github.com/NorfairKing/validity#readme bug-reports: https://github.com/NorfairKing/validity/issues author: Tom Sydney Kerckhove maintainer: syd@cs-syd.eu-copyright: Copyright: (c) 2017-2020 Tom Sydney Kerckhove+copyright: Copyright: (c) 2016-2021 Tom Sydney Kerckhove license: MIT license-file: LICENSE build-type: Simple