Skip to content

Commit 666096f

Browse files
committed
Support GHC 9.0.2
Just requires a few bound relaxations and support for aeson >= 2.0
1 parent 28cc920 commit 666096f

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

proto3-suite.cabal

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ library
4747
if flag(swagger)
4848
exposed-modules: Proto3.Suite.DotProto.Generate.Swagger
4949
Proto3.Suite.DotProto.Generate.Swagger.Wrappers
50-
build-depends: swagger2 >=2.1.6 && <2.7
50+
build-depends: swagger2 >=2.1.6 && <2.8
5151
cpp-options: -DSWAGGER
5252
if flag(swagger-wrapper-format)
5353
hs-source-dirs: src/swagger-wrapper-format
@@ -71,7 +71,7 @@ library
7171
Proto3.Suite.DotProto.Internal
7272
Proto3.Suite.JSONPB.Class
7373

74-
build-depends: aeson >= 1.1.1.0 && < 1.6,
74+
build-depends: aeson >= 1.1.1.0 && < 2.1,
7575
aeson-pretty,
7676
attoparsec >= 0.13.0.1,
7777
base >=4.8 && <5.0,
@@ -139,7 +139,7 @@ test-suite tests
139139
default-language: Haskell2010
140140
build-depends: base >=4.8 && <5.0,
141141
QuickCheck >=2.10 && <2.15,
142-
aeson >= 1.1.1.0 && < 1.6,
142+
aeson >= 1.1.1.0 && < 2.1,
143143
attoparsec >= 0.13.0.1,
144144
base >=4.8 && <5.0,
145145
base64-bytestring >= 1.0.0.1 && < 1.2,

src/Proto3/Suite/JSONPB/Class.hs

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE DefaultSignatures #-}
23
{-# LANGUAGE DeriveGeneric #-}
34
{-# LANGUAGE FlexibleInstances #-}
@@ -71,6 +72,11 @@ import qualified Data.Aeson as A (Encoding, FromJSON (..),
7172
import qualified Data.Aeson.Encoding as E
7273
import qualified Data.Aeson.Encoding.Internal as E
7374
import qualified Data.Aeson.Internal as A (formatError, iparse)
75+
#if MIN_VERSION_aeson(2,0,0)
76+
import qualified Data.Aeson.Key as A
77+
#else
78+
import qualified Data.Aeson.Encoding.Internal as E
79+
#endif
7480
import qualified Data.Aeson.Parser as A (eitherDecodeWith)
7581
import qualified Data.Aeson.Types as A (Object, Pair, Parser,
7682
Series,
@@ -102,6 +108,16 @@ import Proto3.Suite.Types (Enumerated (..), Fixed (..))
102108
import Proto3.Wire.Class (ProtoEnum(..))
103109
import Test.QuickCheck.Arbitrary (Arbitrary(..))
104110

111+
#if MIN_VERSION_aeson(2,0,0)
112+
type Key = A.Key
113+
keyFromText :: Text -> Key
114+
keyFromText = A.fromText
115+
#else
116+
type Key = Text
117+
keyFromText :: Text -> Text
118+
keyFromText = id
119+
#endif
120+
105121
-- * Typeclass definitions
106122

107123
-- | 'A.ToJSON' variant for JSONPB direct encoding via 'A.Encoding'
@@ -164,8 +180,8 @@ eitherDecode = eitherFormatError . A.eitherDecodeWith jsonEOF (A.iparse parseJSO
164180
class Monoid m => KeyValuePB m where
165181
pair :: ToJSONPB v => Text -> v -> Options -> m
166182

167-
instance KeyValuePB A.Series where pair k v opts = E.pair k (toEncodingPB v opts)
168-
instance KeyValuePB [A.Pair] where pair k v opts = pure (k, toJSONPB v opts)
183+
instance KeyValuePB A.Series where pair k v opts = E.pair (keyFromText k) (toEncodingPB v opts)
184+
instance KeyValuePB [A.Pair] where pair k v opts = pure (keyFromText k, toJSONPB v opts)
169185

170186
-- | Construct a monoidal key-value pair, using 'mempty' to represent omission
171187
-- of default values (unless the given 'Options' force their emission).
@@ -183,12 +199,12 @@ k .= v = mk
183199
-- object, or if it is present but its value is null, we produce the default
184200
-- protobuf value for the field type
185201
(.:) :: (FromJSONPB a, HasDefault a) => A.Object -> Text -> A.Parser a
186-
obj .: key = obj .:? key A..!= def
202+
obj .: key = obj .:? keyFromText key A..!= def
187203
where
188204
(.:?) = A.explicitParseFieldMaybe parseJSONPB
189205

190206
parseField :: FromJSONPB a
191-
=> A.Object -> Text -> A.Parser a
207+
=> A.Object -> Key -> A.Parser a
192208
parseField = A.explicitParseField parseJSONPB
193209

194210
-- | >>> isDefault (def @E.Encoding)

0 commit comments

Comments
 (0)