Skip to content

Support aeson-2.0 #121

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion aws-lambda-haskell-runtime.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ library
QuasiQuotes
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
build-depends:
aeson
aeson >2
, base >=4.7 && <5
, bytestring
, case-insensitive
Expand Down
7 changes: 4 additions & 3 deletions src/Aws/Lambda/Runtime/ALB/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Data.Aeson
)
import Data.Aeson.Types (Parser)
import qualified Data.Aeson.Types as T
import qualified Data.Aeson.Key as K
import qualified Data.CaseInsensitive as CI
import Data.HashMap.Strict (HashMap)
import Data.Text (Text)
Expand Down Expand Up @@ -59,7 +60,7 @@ instance FromJSON body => FromJSON (ALBRequest body) where
parseJSON = parseALBRequest parseObjectFromStringField

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

parseALBRequest :: (Object -> Text -> Parser (Maybe body)) -> Value -> Parser (ALBRequest body)
parseALBRequest :: (Object -> T.Key -> Parser (Maybe body)) -> Value -> Parser (ALBRequest body)
parseALBRequest bodyParser (Object v) =
ALBRequest
<$> v .: "path"
Expand Down Expand Up @@ -167,5 +168,5 @@ mkALBResponse code headers payload =
headerToPair :: Header -> T.Pair
headerToPair (cibyte, bstr) = k .= v
where
k = (T.decodeUtf8 . CI.original) cibyte
k = (K.fromText . T.decodeUtf8 . CI.original) cibyte
v = T.decodeUtf8 bstr
7 changes: 4 additions & 3 deletions src/Aws/Lambda/Runtime/APIGateway/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Data.Aeson
(.:?)
)
import Data.Aeson.Types (Parser)
import qualified Data.Aeson.Key as K
import qualified Data.Aeson.Types as T
import qualified Data.CaseInsensitive as CI
import Data.HashMap.Strict (HashMap)
Expand Down Expand Up @@ -70,7 +71,7 @@ instance FromJSON body => FromJSON (ApiGatewayRequest body) where
parseJSON = parseApiGatewayRequest parseObjectFromStringField

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

parseApiGatewayRequest :: (Object -> Text -> Parser (Maybe body)) -> Value -> Parser (ApiGatewayRequest body)
parseApiGatewayRequest :: (Object -> T.Key -> Parser (Maybe body)) -> Value -> Parser (ApiGatewayRequest body)
parseApiGatewayRequest bodyParser (Object v) =
ApiGatewayRequest
<$> v .: "resource"
Expand Down Expand Up @@ -215,5 +216,5 @@ mkApiGatewayResponse code headers payload =
headerToPair :: Header -> T.Pair
headerToPair (cibyte, bstr) = k .= v
where
k = (T.decodeUtf8 . CI.original) cibyte
k = (K.fromText . T.decodeUtf8 . CI.original) cibyte
v = T.decodeUtf8 bstr