Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Text/Toml/Types.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}

Expand All @@ -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)
Expand Down Expand Up @@ -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.
--
Expand Down