Skip to content

Commit fa19268

Browse files
committed
Support aeson-2.0
fixes theam#120
1 parent 0031c3e commit fa19268

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

aws-lambda-haskell-runtime.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ library
5858
QuasiQuotes
5959
ghc-options: -Wall -optP-Wno-nonportable-include-path -Wincomplete-uni-patterns -Wincomplete-record-updates -Wcompat -Widentities -Wredundant-constraints -Wmissing-export-lists -Wpartial-fields -fhide-source-paths -freverse-errors
6060
build-depends:
61-
aeson
61+
aeson >2
6262
, base >=4.7 && <5
6363
, bytestring
6464
, case-insensitive

src/Aws/Lambda/Runtime/ALB/Types.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Data.Aeson
2727
)
2828
import Data.Aeson.Types (Parser)
2929
import qualified Data.Aeson.Types as T
30+
import qualified Data.Aeson.Key as K
3031
import qualified Data.CaseInsensitive as CI
3132
import Data.HashMap.Strict (HashMap)
3233
import Data.Text (Text)
@@ -59,7 +60,7 @@ instance FromJSON body => FromJSON (ALBRequest body) where
5960
parseJSON = parseALBRequest parseObjectFromStringField
6061

6162
-- We need this because API Gateway is going to send us the payload as a JSON string
62-
parseObjectFromStringField :: FromJSON a => Object -> Text -> Parser (Maybe a)
63+
parseObjectFromStringField :: FromJSON a => Object -> T.Key -> Parser (Maybe a)
6364
parseObjectFromStringField obj fieldName = do
6465
fieldContents <- obj .: fieldName
6566
case fieldContents of
@@ -70,7 +71,7 @@ parseObjectFromStringField obj fieldName = do
7071
Null -> pure Nothing
7172
other -> T.typeMismatch "String or Null" other
7273

73-
parseALBRequest :: (Object -> Text -> Parser (Maybe body)) -> Value -> Parser (ALBRequest body)
74+
parseALBRequest :: (Object -> T.Key -> Parser (Maybe body)) -> Value -> Parser (ALBRequest body)
7475
parseALBRequest bodyParser (Object v) =
7576
ALBRequest
7677
<$> v .: "path"
@@ -167,5 +168,5 @@ mkALBResponse code headers payload =
167168
headerToPair :: Header -> T.Pair
168169
headerToPair (cibyte, bstr) = k .= v
169170
where
170-
k = (T.decodeUtf8 . CI.original) cibyte
171+
k = (K.fromText . T.decodeUtf8 . CI.original) cibyte
171172
v = T.decodeUtf8 bstr

src/Aws/Lambda/Runtime/APIGateway/Types.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Data.Aeson
2929
(.:?)
3030
)
3131
import Data.Aeson.Types (Parser)
32+
import qualified Data.Aeson.Key as K
3233
import qualified Data.Aeson.Types as T
3334
import qualified Data.CaseInsensitive as CI
3435
import Data.HashMap.Strict (HashMap)
@@ -70,7 +71,7 @@ instance FromJSON body => FromJSON (ApiGatewayRequest body) where
7071
parseJSON = parseApiGatewayRequest parseObjectFromStringField
7172

7273
-- We need this because API Gateway is going to send us the payload as a JSON string
73-
parseObjectFromStringField :: FromJSON a => Object -> Text -> Parser (Maybe a)
74+
parseObjectFromStringField :: FromJSON a => Object -> T.Key -> Parser (Maybe a)
7475
parseObjectFromStringField obj fieldName = do
7576
fieldContents <- obj .: fieldName
7677
case fieldContents of
@@ -81,7 +82,7 @@ parseObjectFromStringField obj fieldName = do
8182
Null -> pure Nothing
8283
other -> T.typeMismatch "String or Null" other
8384

84-
parseApiGatewayRequest :: (Object -> Text -> Parser (Maybe body)) -> Value -> Parser (ApiGatewayRequest body)
85+
parseApiGatewayRequest :: (Object -> T.Key -> Parser (Maybe body)) -> Value -> Parser (ApiGatewayRequest body)
8586
parseApiGatewayRequest bodyParser (Object v) =
8687
ApiGatewayRequest
8788
<$> v .: "resource"
@@ -215,5 +216,5 @@ mkApiGatewayResponse code headers payload =
215216
headerToPair :: Header -> T.Pair
216217
headerToPair (cibyte, bstr) = k .= v
217218
where
218-
k = (T.decodeUtf8 . CI.original) cibyte
219+
k = (K.fromText . T.decodeUtf8 . CI.original) cibyte
219220
v = T.decodeUtf8 bstr

0 commit comments

Comments
 (0)