From 33971287445c5e2531d9605a287486dfc3cbe1da Mon Sep 17 00:00:00 2001 From: mirokuratczyk Date: Thu, 27 Jan 2022 13:55:24 -0500 Subject: [PATCH] aeson-2.0.0.0 support --- src/Text/Toml/Types.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Text/Toml/Types.hs b/src/Text/Toml/Types.hs index 4027802..06a95f8 100644 --- a/src/Text/Toml/Types.hs +++ b/src/Text/Toml/Types.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} @@ -19,6 +20,9 @@ import Text.Parsec import Data.Aeson.Types import Data.HashMap.Strict (HashMap) import qualified Data.HashMap.Strict as M +#if MIN_VERSION_aeson(2,0,0) +import qualified Data.Aeson.KeyMap as KM +#endif import Data.Int (Int64) import Data.List (intersect) import Data.Set (Set) @@ -190,9 +194,20 @@ instance (ToBsJSON a) => ToBsJSON (Vector a) where -- | Provide a 'toBsJSON' instance to the 'NTable'. instance (ToBsJSON v) => ToBsJSON (M.HashMap Text v) where +#if MIN_VERSION_aeson(2,0,0) + toBsJSON = Object . KM.fromHashMapText . M.map toBsJSON +#else toBsJSON = Object . M.map toBsJSON +#endif {-# INLINE toBsJSON #-} +-- | 'ToBsJSON' instance for 'KeyMap'. +#if MIN_VERSION_aeson(2,0,0) +instance (ToBsJSON v) => ToBsJSON (KM.KeyMap v) where + toBsJSON = Object . KM.map toBsJSON + {-# INLINE toBsJSON #-} +#endif + -- | 'ToBsJSON' instances for the 'TValue' type that produce Aeson (JSON) -- in line with BurntSushi's language agnostic TOML test suite. --