eclipse-ee4j / eclipse-ee4j/jersey
Jersey 2.29.1 Response Encoding Issue with AWS Api Gateway+ AWS Lambda +Scala
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
I am having an issue in returning special characters(Chinese characters). My flow is following AWS API Gateway calls Lambda (Contains Jersey 2.29.1)
Before returning response I am printing it in logs and on cloud-watch logs, I can see the response as following
{
"names": [
"骅威文化股份有限公司"
]
}
But when the response returned by the API is following(which is encoded in ISO-8859-1)
{
"names": [
"éªå¨æåè¡ä»½æéå¬å¸"
]
}
The code which I am using to return the response is
return Response.status(200).header("Access-Control-Allow-Origin", "*").entity(gson.toJson(response)).build()
with these annotations to the returning method
@Consumes(Array(MediaType.APPLICATION_JSON))
@Produces(Array(MediaType.APPLICATION_JSON))
I have tried all the options mentioned in community blogs like changing the annotation to add "UTF-8" string in the produces annotation like @Produces(Array(MediaType.APPLICATION_JSON + ";charset=UTF-8"))
. To add the Content-Type header in the Response builder code I used is return Response.status(200).encoding("UTF-8").header("Access-Control-Allow-Origin", "*").entity(gson.toJson(response)).build().
After this, I cloned the jersey repo version 2.29.1 and looked in the code that the default encoding used by it is "ISO-8859-1". Here you can see line#32 of org.glassfish.jersey.jdk.connector.internal.HttpParser contains
private static final String ENCODING = "ISO-8859-1";
Is there a way to either set some property or add some custom Filter so that I can update this encoding to use UTF-8 and have a correct response?
Contributor guide
Assessment
This issue has not been assessed yet.