Skip to content

Commit 967316a

Browse files
committed
Support aeson-2.0
1 parent 71e4aba commit 967316a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

aeson-commit.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ description:
1717
category: Text, Web, JSON
1818
build-type: Simple
1919
extra-source-files:
20-
README.md
2120
CHANGELOG.md
21+
README.md
2222

2323
source-repository head
2424
type: git
@@ -30,7 +30,7 @@ library
3030
default-language: Haskell2010
3131
ghc-options: -Wall -Wno-name-shadowing
3232
build-depends:
33-
aeson >=1.4 && <2
33+
aeson >=1.4 && <2.1
3434
, base >=4.10 && <5
3535
, mtl >=2.2 && <3
3636
, text >=1.2 && <2
@@ -42,7 +42,7 @@ test-suite tasty
4242
default-language: Haskell2010
4343
ghc-options: -Wall -Wno-name-shadowing
4444
build-depends:
45-
aeson >=1.4 && <2
45+
aeson >=1.4 && <2.1
4646
, aeson-commit
4747
, aeson-qq >=0.8 && <1
4848
, base >=4.10 && <5

src/Data/Aeson/Commit.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2+
{-# LANGUAGE CPP #-}
23

34
{-|
45
Commitment mechanism for aeson 'Parser'.
@@ -40,8 +41,12 @@ module Data.Aeson.Commit
4041
import Control.Applicative (Alternative (..))
4142
import Control.Monad.Except
4243
import Data.Aeson.Types
43-
import Data.Text (Text)
4444
import Data.Void (Void, absurd)
45+
#if MIN_VERSION_aeson(2,0,0)
46+
import qualified Data.Aeson.Key as Key
47+
#else
48+
import Data.Text (Text)
49+
#endif
4550

4651
-- | A 'Parser' that has _two_ failure modes; recoverable and non-recoverable.
4752
-- The default, recoverable failure is the equivalent to aeson's default 'Parser' behavior.
@@ -87,7 +92,12 @@ runCommit (Commit f) = runExceptT f >>= either handleErrors pure
8792

8893
-- | Convenience wrapper around 'commit' for when the commit is checking whether a key is present in some object.
8994
-- If it is, it will commit and append the key to the JSONPath of the inner context through '<?>', which will give nicer error messages.
95+
96+
#if MIN_VERSION_aeson(2,0,0)
97+
(.:>) :: FromJSON a => Object -> Key.Key -> (a -> Parser b) -> Commit b
98+
#else
9099
(.:>) :: FromJSON a => Object -> Text -> (a -> Parser b) -> Commit b
100+
#endif
91101
(o .:> k) cont = commit (o .: k) (\v -> cont v <?> Key k)
92102

93103
-- | Turn a 'Parser' into a 'Commit'

0 commit comments

Comments
 (0)