question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Requests with application/json Content-Type do not correctly assume UTF-8 charset

See original GitHub issue
  • Framework version: 1.1.1 - 1.1.3
  • Implementations: All

Scenario

It seems that the changes for #150 broke the assumption that all JSON is UTF-8, by definition.

Expected behavior

Parsing a JSON request body to a Java type should assume UTF-8 charset.

Actual behavior

It does not correctly handle characters out of ascii set.

Steps to reproduce

Send request with appplication/json in the Content-Type header and strange characters such as » in the JSON body. It will not be correctly parsed and throw a bad request.

If you set the Content-Type header to application/json; charset=UTF-8 then it works fine, but should not be necessary and most REST clients won’t do it.

Full log output

Invalid UTF-8 middle byte 0x65\\n at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 13]\\n at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream);

Thanks for your support!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
sapessicommented, Jul 27, 2018

Perhaps I could add a field for this in the ContainerConfig object, default it to ISO-8859-1, but give you the ability to change this whenever you want:

LambdaContainerHandler.getContainerConfig()
    .setDefaultContentCharset(StandardCharsets.UTF_8.name())

Thoughts?

1reaction
sapessicommented, Aug 27, 2018

That’s the plan.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does "Content-type: application/json; charset=utf-8 ...
Content -type: application/json; charset=utf-8 designates the content to be in JSON format, encoded in the UTF-8 character encoding. Designating the encoding ...
Read more >
Make default charset UTF-8 when using `receiveText` for ...
Request with Content-Type: application/json is decoded not as UTF-8, while request with Content-Type: application/json; charset=utf-8 is decoded correctly.
Read more >
Support non-Unicode character encoding in Azure Logic Apps
If you're using the Request trigger for text/plain content, you must set the charset parameter that is in the call's Content-Type header.
Read more >
Character set in JSON file - Progress Community
What is the correct character set requested by the customer in the output file? I assume ... :ContentType('application/json;charset=UTF-8').
Read more >
What does “Content-type: application/json; charset=utf-8 ...
Designating the encoding is somewhat redundant for JSON, since the default (only?) encoding for JSON is UTF-8. So in this case the receiving...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found