Ticket #225 (closed defect: fixed)
Encoding issue with jax-rs method with string argument to handle put/post of json data
| Reported by: | jgou | Owned by: | jgou |
|---|---|---|---|
| Priority: | major | Milestone: | 0.4 |
| Component: | modules/kauri-routing | Version: | trunk |
| Keywords: | Cc: |
Description
When using a jax-rs method with string argument to handle a put or post of a json payload (utf-8), the string given as argument contains invalid characters when there are non-ascii characters in the json data. This was seen on a Windows OS, so it may be related to the OS-encoding.
Encoding issue occurs with:
@PUT
@Consumes("application/json")
public void updateFoo(String jsonString) {
// ...
}
Workaround is to use a method with a byte-array argument and decode it yourself:
@PUT
@Consumes("application/json")
public void updateFoo(byte[] jsonBytes) {
String jsonString = new String(bytes,"UTF-8");
// ...
}
However it would be nice if there could be some fix to jax-rs (or even kauri) that makes it possible to use the String-argument methods with right encoding.
Change History
comment:2 in reply to: ↑ 1 Changed 4 years ago by jgou
Replying to mpo:
Without having looked into the details, but just to ban the obvious.
Did you try @Consumes("application/json;charset=UTF-8") ?
Yes, I did try but with awkward result: when adding the charset to the 'consumes' annotation, the method isn't used at all (producing an error that no jax-rs mapping was found). Looks like the used jax-rs implementation doesn't like it ?
comment:3 Changed 3 years ago by mpo
Rethinking this a bit I realize that my earlier proposal doesn't really make sense.
The client is in charge and will be setting the MimeType? (or not if default utf-8 is to be used) when performing the PUT.
So it really is the receiving system that should comply and do the correct thing.
(Meaning your workaround is actually a good one, but I agree the underlaying system could do a better effort probably)
Various strategies to proceed:
- isolate the issue on the level of restlet's jax-rs implementation and open an issue there (+ hope for a solution)
- same as above + delve into restlet to produce a fix (+hope on it being applied)
- look into plugable jax-rs mapping logic maybe to handle this mimetype (not entirely sure how/if)
comment:4 follow-up: ↓ 6 Changed 3 years ago by jgou
Someone started a thread about this issue on the restlet discussion list: http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2626010
comment:5 Changed 3 years ago by freya
- Owner changed from bruno to jgou
- Status changed from new to assigned
- Milestone changed from 0.4 to 0.4.1
comment:6 in reply to: ↑ 4 Changed 3 years ago by jgou
Replying to jgou:
Someone started a thread about this issue on the restlet discussion list: http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2626010
restlet issue tracked in http://restlet.tigris.org/issues/show_bug.cgi?id=1147
comment:7 Changed 3 years ago by jgou
should be fixed in restlet r6766 , so to resolve this issue we should upgrade restlet dependencies (and verify)
Without having looked into the details, but just to ban the obvious.
Did you try @Consumes("application/json;charset=UTF-8") ?