pkg: add support for aeson 2.2, add upper bound

This commit is contained in:
Simon Michael 2023-07-01 08:10:44 -10:00
parent e3bf66755a
commit 1a0b745c28
4 changed files with 25 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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