eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
690 stars 353 forks source link

Error parsing media type 'application/json; charset: utf-8' #5290

Open chall324 opened 1 year ago

chall324 commented 1 year ago

Hi,

Hope you're well.

Getting this error, it's mostly the fault of the API end point returning a non standard response: 'charset: utf-8' instead of 'charset=utf-8'

Any chance of throwing in a fix to treat charset: utf-8 as if it returned the standard responce?

Thanks, Chris

jansupol commented 1 year ago

Hi, I am not sure this is generally fixable on our side. For parsing JSON, we usually use 3d party JSON libs, such as Jackson, Moxy, JSON-B / JSON-P... These libs support JAX-RS and have a provider that checks the media type and decide if the provider supports it or not.

Given you have not specified the provider you use in your project, I'd suggest you add a provider which would inherit from the provider you want to use, and implement isReadable/isWritable so that it replaces charset when calling return super.isWritable()/isReadeble. The same with read/write of that MessageBodyReader/Writer (which I assume is where it fails for you.

zUniQueX commented 1 year ago

Hi, couldn't this be achieved by adding a ContainerRequestFilter/ClientResponseFilter correcting the header? According to the docs these are getting invoked before reading the entity.