Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Failing creating a JSD request through REST-api with special characters "Invalid UTF-8 middle byte"

Pontus Ridderström
Contributor
September 13, 2018

Hi i am currently making an integration which should automatically generate Incidents. 

I do however have a problem as the client want to include Swedish characters "ÅÄÖ" in the issue.

When i try to create a request equal to the JSON below. 
{
"serviceDeskId":"62",
"requestTypeId":"135",
"requestFieldValues":
    {
    "summary":"[OP5 Generated]GMS - Garantisystem för NCTS loggövervakning företagstest"
     }
}

I get the response 
"{"message":"Invalid UTF-8 middle byte 0x72\n at [Source: org.apache.catalina.connector.CoyoteInputStream@25588092; line: 1, column: 116]" 


When i change the summary text to not containing "ÅÄÖ" characters. The issue is created without a problem. 

The headers that are set are "Accept = application/json", "Content-type=application/json" and "Authenticate = {basic auth string}) 

The request is being made with a Java application using the "Apache http" library. 



1 answer

1 accepted

0 votes
Answer accepted
Pontus Ridderström
Contributor
September 13, 2018

I found the solution. 
When applying a data to a http Post request with the "Apache http" library, you set an entity on the request object. 
When creating and mapping the JSON string to the Entity object you need to apply an encoding.

"OLD" = not working

String jsonData = {STRING WITH JSON STRUCTURE}
StringEntity entity = new StringEntity(jsonData);
httpPost.setEntity(entity);

"NEW" = working
String jsonData = {STRING WITH JSON STRUCTURE}
StringEntity entity = new StringEntity(jsonData, "UTF-8");
httpPost.setEntity(entity);

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events