Skip to content

Commit fda1535

Browse files
authored
Allow to build with aeson >=2, fixes #36 (#37)
1 parent cdd4c3f commit fda1535

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Data/Aeson/Encode/Pretty.hs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
1+
{-# LANGUAGE OverloadedStrings, RecordWildCards, CPP #-}
22

33
-- |Aeson-compatible pretty-printing of JSON 'Value's.
44
module Data.Aeson.Encode.Pretty (
@@ -54,11 +54,15 @@ module Data.Aeson.Encode.Pretty (
5454
keyOrder
5555
) where
5656

57+
#if MIN_VERSION_aeson(2,0,0)
58+
import qualified Data.Aeson.Key as AK
59+
import qualified Data.Aeson.KeyMap as AKM
60+
#endif
5761
import Data.Aeson (Value(..), ToJSON(..))
5862
import qualified Data.Aeson.Text as Aeson
5963
import Data.ByteString.Lazy (ByteString)
6064
import Data.Function (on)
61-
import qualified Data.HashMap.Strict as H (toList)
65+
import qualified Data.HashMap.Strict as H (toList, mapKeys)
6266
import Data.List (intersperse, sortBy, elemIndex)
6367
import Data.Maybe (fromMaybe)
6468
import Data.Semigroup ((<>))
@@ -170,10 +174,16 @@ fromValue :: PState -> Value -> Builder
170174
fromValue st@PState{..} val = go val
171175
where
172176
go (Array v) = fromCompound st ("[","]") fromValue (V.toList v)
173-
go (Object m) = fromCompound st ("{","}") fromPair (pSort (H.toList m))
177+
go (Object m) = fromCompound st ("{","}") fromPair (pSort (toList' m))
174178
go (Number x) = fromNumber st x
175179
go v = Aeson.encodeToTextBuilder v
176180

181+
#if MIN_VERSION_aeson(2,0,0)
182+
toList' = fmap (\(k, v) -> (AK.toText k, v)) . AKM.toList
183+
#else
184+
toList' = H.toList
185+
#endif
186+
177187
fromCompound :: PState
178188
-> (Builder, Builder)
179189
-> (PState -> a -> Builder)

aeson-pretty.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cabal-version: 2.0
12
name: aeson-pretty
23
version: 0.8.8
34
license: BSD3
@@ -7,7 +8,6 @@ copyright: Copyright 2011 Falko Peters
78
author: Falko Peters <[email protected]>
89
maintainer: Falko Peters <[email protected]>
910
stability: experimental
10-
cabal-version: >= 1.8
1111
homepage: http://github.com/informatikr/aeson-pretty
1212
bug-reports: http://github.com/informatikr/aeson-pretty/issues
1313
build-type: Simple
@@ -40,7 +40,7 @@ library
4040
Data.Aeson.Encode.Pretty
4141

4242
build-depends:
43-
aeson >= 1.0,
43+
aeson ^>= 1.0 || ^>=1.1 || ^>=1.2 || ^>=1.3 || ^>=1.4 || ^>=1.5 || ^>=2.0,
4444
base >= 4.5,
4545
base-compat >= 0.9,
4646
bytestring >= 0.9,

0 commit comments

Comments
 (0)