Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GHC 9.0.2 #176

Merged
merged 1 commit into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions proto3-suite.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ library
if flag(swagger)
exposed-modules: Proto3.Suite.DotProto.Generate.Swagger
Proto3.Suite.DotProto.Generate.Swagger.Wrappers
build-depends: swagger2 >=2.1.6 && <2.7
build-depends: swagger2 >=2.1.6 && <2.8
cpp-options: -DSWAGGER
if flag(swagger-wrapper-format)
hs-source-dirs: src/swagger-wrapper-format
Expand All @@ -71,11 +71,11 @@ library
Proto3.Suite.DotProto.Internal
Proto3.Suite.JSONPB.Class

build-depends: aeson >= 1.1.1.0 && < 1.6,
build-depends: aeson >= 1.1.1.0 && < 2.1,
aeson-pretty,
attoparsec >= 0.13.0.1,
base >=4.8 && <5.0,
base64-bytestring >= 1.0.0.1 && < 1.2,
base64-bytestring >= 1.0.0.1 && < 1.3,
binary >=0.8.3,
bytestring >=0.10.6.0 && <0.11.0,
deepseq ==1.4.*,
Expand Down Expand Up @@ -139,10 +139,10 @@ test-suite tests
default-language: Haskell2010
build-depends: base >=4.8 && <5.0,
QuickCheck >=2.10 && <2.15,
aeson >= 1.1.1.0 && < 1.6,
aeson >= 1.1.1.0 && < 2.1,
attoparsec >= 0.13.0.1,
base >=4.8 && <5.0,
base64-bytestring >= 1.0.0.1 && < 1.2,
base64-bytestring >= 1.0.0.1 && < 1.3,
bytestring >=0.10.6.0 && <0.11.0,
cereal >= 0.5.1 && <0.6,
containers >=0.5 && < 0.7,
Expand Down
24 changes: 20 additions & 4 deletions src/Proto3/Suite/JSONPB/Class.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
Expand Down Expand Up @@ -71,6 +72,11 @@ import qualified Data.Aeson as A (Encoding, FromJSON (..),
import qualified Data.Aeson.Encoding as E
import qualified Data.Aeson.Encoding.Internal as E
import qualified Data.Aeson.Internal as A (formatError, iparse)
#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.Key as A
#else
import qualified Data.Aeson.Encoding.Internal as E
#endif
import qualified Data.Aeson.Parser as A (eitherDecodeWith)
import qualified Data.Aeson.Types as A (Object, Pair, Parser,
Series,
Expand Down Expand Up @@ -102,6 +108,16 @@ import Proto3.Suite.Types (Enumerated (..), Fixed (..))
import Proto3.Wire.Class (ProtoEnum(..))
import Test.QuickCheck.Arbitrary (Arbitrary(..))

#if MIN_VERSION_aeson(2,0,0)
type Key = A.Key
keyFromText :: Text -> Key
keyFromText = A.fromText
#else
type Key = Text
keyFromText :: Text -> Text
keyFromText = id
#endif

-- * Typeclass definitions

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

instance KeyValuePB A.Series where pair k v opts = E.pair k (toEncodingPB v opts)
instance KeyValuePB [A.Pair] where pair k v opts = pure (k, toJSONPB v opts)
instance KeyValuePB A.Series where pair k v opts = E.pair (keyFromText k) (toEncodingPB v opts)
instance KeyValuePB [A.Pair] where pair k v opts = pure (keyFromText k, toJSONPB v opts)

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

parseField :: FromJSONPB a
=> A.Object -> Text -> A.Parser a
=> A.Object -> Key -> A.Parser a
parseField = A.explicitParseField parseJSONPB

-- | >>> isDefault (def @E.Encoding)
Expand Down