xp-framework / xp-framework

XP 5.X - superseded by https://github.com/xp-framework/core
33 stars 24 forks source link

JsonParser throws FormatException when a json value contains the character "–" #362

Closed haimich closed 9 years ago

haimich commented 10 years ago

When trying to deserialize the JSON string

{
  "badForXp": "–"
}

I get the following exception:

text.parser.generic.ParseException (Cannot decode string lang.types.Bytes(1)@{"} to iso-8859-1)

Allthough it looks like a dash the character is actually a little shorter than the normal dash.

haimich commented 10 years ago

I found that the error handling behavior was introduced with https://github.com/xp-framework/xp-framework/issues/324. After talking to @kiesel we decided that the following would be the best approach to fix the issue:

For testing purposes: the hex code of the dash character I'm having trouble with is e2 80 93 ("EN DASH").

thekid commented 10 years ago

Thank you for reporting this issue. The solution to pass a target encoding is basically OK as it's the way we've dealt with this in other APIs so far. The option to pass it to $response->data() (and $response->content(), by the way) is better since it's the response's encoding we're dealing with, not the request's.

Pull requests are welcome!