Default application/json character set with entity(as[String]) is not UTF8

362 views
Skip to first unread message

Otto Chrons

unread,
Jun 16, 2014, 4:24:41 AM6/16/14
to spray...@googlegroups.com
I have a simple route that takes JSON string as POST request entity:

(path("createDistricts") & post & requestEntityPresent & parameters('projectId)) { (projectId) =>
          entity(as[String]) { districtJson =>
            ctx =>

Now, if I call it with the following curl statement, the JSON string is not decoded as UTF8 (but probably as ISO-8859):

curl -H "Content-Type: application/json" -X POST -d @districts.json "http://localhost:9099/api/createDistricts?projectId=Test"

But forcing the character set to be UTF-8, it works ok.

curl -H "Content-Type: application/json; charset=UTF-8" -X POST -d @districts.json "http://localhost:9099/api/createDistricts?projectId=Test"

Shouldn't the default charset for "application/json" be UTF-8 also when decoding the entity? I recall there was a similar issue with JSON encoding that got fixed.

I'm using Spray 1.3.1, Scala 2.10.3 and Akka 2.3.0

- Otto

Mathias Doenitz

unread,
Jun 20, 2014, 9:30:50 AM6/20/14
to spray...@googlegroups.com
Otto,

what JSON support are you using?
The SprayJsonSupport appears to behave exactly as you’d like it to:
https://github.com/spray/spray/blob/master/spray-httpx/src/main/scala/spray/httpx/SprayJsonSupport.scala#L36

Can you provide us with a SSCCE (http://sscce.org/) demonstrating the problem?

Cheers,
Mathias

---
mat...@spray.io
http://spray.io
> --
> You received this message because you are subscribed to the Google Groups "spray.io User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
> Visit this group at http://groups.google.com/group/spray-user.
> To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/01438fa2-66bd-4a38-a6f6-8f7ee61bca2e%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Otto Chrons

unread,
Jun 23, 2014, 2:47:03 AM6/23/14
to spray...@googlegroups.com
Hi,

We're using Jackson (as the project was originally in Java, later rewritten in Scala) and doing the deserialization "manually" after Spray has already decoded the string. Perhaps the solution would be to write an unmarshaller for Jackson, similar to what SprayJson has?

- Otto


You received this message because you are subscribed to a topic in the Google Groups "spray.io User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/spray-user/BZTIVQWzObo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to spray-user+...@googlegroups.com.

Mathias Doenitz

unread,
Jun 23, 2014, 4:01:13 AM6/23/14
to spray...@googlegroups.com
Otto,

if you are doing the deserialisation manually then it’s likely that it is in this step that you need to apply the UTF-9 decoding.

Cheers,
Mathias

---
mat...@spray.io
http://spray.io

> To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/CACHSF7hPx-ajy6RVvH5h7cSdqVhc1iOfbH2vUMss_Cba8Wxurg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages