spray / spray-json

A lightweight, clean and simple JSON implementation in Scala
Apache License 2.0
974 stars 190 forks source link

UTF-8 unmarshalling doesn't decode the first character correctly #169

Closed zeninpalm closed 9 years ago

zeninpalm commented 9 years ago

Hi, I'm pretty new to spray-json, so maybe I'm asking an already solved problem! Somehow I ran into an utf-8 encoding problem with spray-json unmarshalling, maybe someone could tell me what the problem is. I just cloned akka-http-rest template with Typesafe activator, then I changed UsersServiceRoute like this:

pathEndOrSingleSlash {
      get {
        complete(getUsers().map(_.toJson))
      } ~
        post {
            entity(as[UserEntity]) { userEntity =>
                complete(createUser(userEntity))
            }
        }
    } 

so now I may create new users from POST request, and everything works fine with ASC-II encoding requests. Then I tried one request with UTF-8 characters in it, the unmarshalling behaves wierdly, just like the following:

request:

{"id":1, "username":"用户你好", "passworld":"1235678"}

response

{
    "id": 7,
    "username": "ç��户你好",
    "password": "$2a$10$hzHaFjuPdzJodKATkvAEQuWXq7QDN1gTA0QNWgtuLPeIf8bKGN2Be"
}

As you can see, all the utf-8 characters are correct, except the first one, I'm totally confused, what should I do?

zeninpalm commented 9 years ago

Someone already reported this issue, I'm closing