Skip to content

Commit

Permalink
Allow to build with aeson >=2, fixes informatikr#36
Browse files Browse the repository at this point in the history
  • Loading branch information
hasufell committed Oct 9, 2021
1 parent cdd4c3f commit e902ab8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions Data/Aeson/Encode/Pretty.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
{-# LANGUAGE OverloadedStrings, RecordWildCards, CPP #-}

-- |Aeson-compatible pretty-printing of JSON 'Value's.
module Data.Aeson.Encode.Pretty (
Expand Down Expand Up @@ -54,11 +54,15 @@ module Data.Aeson.Encode.Pretty (
keyOrder
) where

#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.Key as AK
import qualified Data.Aeson.KeyMap as AKM
#endif
import Data.Aeson (Value(..), ToJSON(..))
import qualified Data.Aeson.Text as Aeson
import Data.ByteString.Lazy (ByteString)
import Data.Function (on)
import qualified Data.HashMap.Strict as H (toList)
import qualified Data.HashMap.Strict as H (toList, mapKeys)
import Data.List (intersperse, sortBy, elemIndex)
import Data.Maybe (fromMaybe)
import Data.Semigroup ((<>))
Expand Down Expand Up @@ -170,10 +174,16 @@ fromValue :: PState -> Value -> Builder
fromValue st@PState{..} val = go val
where
go (Array v) = fromCompound st ("[","]") fromValue (V.toList v)
go (Object m) = fromCompound st ("{","}") fromPair (pSort (H.toList m))
go (Object m) = fromCompound st ("{","}") fromPair (pSort (toList' m))
go (Number x) = fromNumber st x
go v = Aeson.encodeToTextBuilder v

#if MIN_VERSION_aeson(2,0,0)
toList' = fmap (\(k, v) -> (AK.toText k, v)) . AKM.toList
#else
toList' = H.toList
#endif

fromCompound :: PState
-> (Builder, Builder)
-> (PState -> a -> Builder)
Expand Down
4 changes: 2 additions & 2 deletions aeson-pretty.cabal
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cabal-version: 2.0
name: aeson-pretty
version: 0.8.8
license: BSD3
Expand All @@ -7,7 +8,6 @@ copyright: Copyright 2011 Falko Peters
author: Falko Peters <[email protected]>
maintainer: Falko Peters <[email protected]>
stability: experimental
cabal-version: >= 1.8
homepage: http://github.com/informatikr/aeson-pretty
bug-reports: http://github.com/informatikr/aeson-pretty/issues
build-type: Simple
Expand Down Expand Up @@ -40,7 +40,7 @@ library
Data.Aeson.Encode.Pretty

build-depends:
aeson >= 1.0,
aeson ^>= 1.0 || ^>=1.1 || ^>=1.2 || ^>=1.3 || ^>=1.4 || ^>=1.5 || ^>=2.0,
base >= 4.5,
base-compat >= 0.9,
bytestring >= 0.9,
Expand Down

0 comments on commit e902ab8

Please sign in to comment.