diff --git a/hledger-lib/Hledger/Data/Json.hs b/hledger-lib/Hledger/Data/Json.hs index d0d6095a5..a3ac1f506 100644 --- a/hledger-lib/Hledger/Data/Json.hs +++ b/hledger-lib/Hledger/Data/Json.hs @@ -2,6 +2,7 @@ JSON instances. Should they be in Types.hs ? -} +{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} @@ -67,7 +68,13 @@ instance (Integral a, ToJSON a) => ToJSON (DecimalRaw a) where toJSON = object . decimalKV toEncoding = pairs . mconcat . decimalKV -decimalKV :: (KeyValue kv, Integral a, ToJSON a) => DecimalRaw a -> [kv] +decimalKV :: ( +#if MIN_VERSION_aeson(2,2,0) + KeyValue e kv, +#else + KeyValue kv, +#endif + Integral a, ToJSON a) => DecimalRaw a -> [kv] decimalKV d = let d' = if decimalPlaces d <= 10 then d else roundTo 10 d in [ "decimalPlaces" .= decimalPlaces d' , "decimalMantissa" .= decimalMantissa d' @@ -102,7 +109,13 @@ instance ToJSON Posting where toJSON = object . postingKV toEncoding = pairs . mconcat . postingKV -postingKV :: KeyValue kv => Posting -> [kv] +postingKV :: +#if MIN_VERSION_aeson(2,2,0) + KeyValue e kv +#else + KeyValue kv +#endif + => Posting -> [kv] postingKV Posting{..} = [ "pdate" .= pdate , "pdate2" .= pdate2 @@ -144,7 +157,13 @@ instance ToJSON Account where toJSON = object . accountKV toEncoding = pairs . mconcat . accountKV -accountKV :: KeyValue kv => Account -> [kv] +accountKV :: +#if MIN_VERSION_aeson(2,2,0) + KeyValue e kv +#else + KeyValue kv +#endif + => Account -> [kv] accountKV a = [ "aname" .= aname a , "aebalance" .= aebalance a diff --git a/hledger-lib/package.yaml b/hledger-lib/package.yaml index e75aec710..8a2aa4b47 100644 --- a/hledger-lib/package.yaml +++ b/hledger-lib/package.yaml @@ -34,7 +34,7 @@ extra-source-files: dependencies: - base >=4.14 && <4.19 - base-compat -- aeson >=1 +- aeson >=1 && <2.3 - aeson-pretty - ansi-terminal >=0.9 - array diff --git a/hledger-web/package.yaml b/hledger-web/package.yaml index 0b2d1eded..e493e070d 100644 --- a/hledger-web/package.yaml +++ b/hledger-web/package.yaml @@ -104,7 +104,7 @@ library: dependencies: - hledger-lib >=1.30.99 && <1.31 - hledger >=1.30.99 && <1.31 - - aeson >=1 + - aeson >=1 && <2.3 - base64 - blaze-html - blaze-markup diff --git a/hledger/package.yaml b/hledger/package.yaml index 8e43664a3..7958b7207 100644 --- a/hledger/package.yaml +++ b/hledger/package.yaml @@ -101,7 +101,7 @@ ghc-options: dependencies: - base >=4.14 && <4.19 - hledger-lib >=1.30.99 && <1.31 -- aeson >=1 +- aeson >=1 && <2.3 - ansi-terminal >=0.9 - bytestring - cmdargs >=0.10