Skip to content

Commit b4160d9

Browse files
committed
aeson compat
1 parent f477e96 commit b4160d9

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

bugsnag/bugsnag.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ library
4040
Network.Bugsnag.Notify
4141
Network.Bugsnag.StackFrame
4242
other-modules:
43-
Paths_bugsnag
43+
Data.Aeson.Compat
4444
hs-source-dirs:
4545
src
4646
default-extensions:

bugsnag/package.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ default-extensions:
4646

4747
library:
4848
source-dirs: src
49+
other-modules:
50+
- Data.Aeson.Compat
4951
dependencies:
5052
- Glob >= 0.9.0
5153
- aeson

bugsnag/src/Data/Aeson/Compat.hs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{-# LANGUAGE CPP #-}
2+
3+
module Data.Aeson.Compat
4+
(
5+
-- * Key
6+
Key
7+
, fromText
8+
, toText
9+
10+
-- * KeyMap
11+
, KeyMap
12+
, empty
13+
, null
14+
, singleton
15+
, fromList
16+
, toList
17+
, unionWith
18+
19+
-- * Etc.
20+
, Pair
21+
, Value(Object)
22+
, Object
23+
, object
24+
, (.=)
25+
) where
26+
27+
import Data.Aeson.Types (Pair, Value(Object), Object, object, (.=))
28+
#if MIN_VERSION_aeson(2, 0, 0)
29+
import Data.Aeson.Key (Key, fromText, toText)
30+
import Data.Aeson.KeyMap (KeyMap, empty, fromList, null, singleton, toList, unionWith)
31+
-- Avoid unused-packages (unordered-containers) warning for this path
32+
import Data.HashMap.Strict ()
33+
#else
34+
import Prelude (id)
35+
36+
import Data.HashMap.Strict (HashMap, empty, fromList, null, singleton, toList, unionWith)
37+
import Data.Text (Text)
38+
39+
type Key = Text
40+
type KeyMap = HashMap Text
41+
42+
fromText :: Text -> Key
43+
fromText = id
44+
45+
toText :: Key -> Text
46+
toText = id
47+
#endif

bugsnag/src/Network/Bugsnag/MetaData.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ module Network.Bugsnag.MetaData
66

77
import Prelude
88

9-
import Data.Aeson (KeyValue ((.=)), Object, Value (..), object)
10-
import qualified Data.Aeson as Aeson
11-
import qualified Data.Aeson.Types as Aeson
12-
import qualified Data.Aeson.KeyMap
9+
import Data.Aeson.Compat ((.=), Value(Object), Object, object)
10+
import qualified Data.Aeson.Compat as Aeson
1311

1412
newtype MetaData = MetaData
1513
{ unMetaData :: Object
@@ -24,7 +22,7 @@ instance Semigroup MetaData where
2422
MetaData x <> MetaData y = MetaData $ unionObjects y x
2523
where
2624
unionObjects :: Object -> Object -> Object
27-
unionObjects = Data.Aeson.KeyMap.unionWith unionValues
25+
unionObjects = Aeson.unionWith unionValues
2826

2927
unionValues (Object a) (Object b) = Object $ unionObjects a b
3028
unionValues a _ = a
@@ -39,7 +37,7 @@ metaData
3937
-> [Aeson.Pair]
4038
-- ^ The Key-Values themselves
4139
-> MetaData
42-
metaData key = MetaData . Data.Aeson.KeyMap.fromList . pure . (key .=) . object
40+
metaData key = MetaData . Aeson.fromList . pure . (key .=) . object
4341

4442
-- $details
4543
--

0 commit comments

Comments
 (0)