I'm using read method of TypeAdapter to read a Json message where some values consists of strings with white spaces.
It seems that readString, skipValue or any method to consume the json value (with white spaces) do not work correctly and drives the app to a MalFormedException trying to consume next characters.
Debugging the app I found that pointer position is in the white space when the exception occure, so it seems that for some reason the parser assumes that the end of the value is in the space and not in the the next comma. Requesting the data from the browser I see that all names and values are wrapped in double quotes, but on JsonReader there's no double quotes. There's some property that I must change? Lenient property is set to true, I cannot find any other property to change this behavior.
Can you please check it out? JsonReader is a great tool but this little issue is very prohibitive. Thanks
Same problem in our project. We use Gson 2.7.
@rmpt @hgschwibbe
Try this. It's fix for me
gson.fromJson(gson.toJson(<your_data>), YourClassName::class.java)
@rmpt @hgschwibbe
Try this. It's fix for me
gson.fromJson(gson.toJson(<your_data>), YourClassName::class.java)
Thanks @osip-000 ! it worked for me also
mark
Could you please provide an example JSON string and the code for reading it for which the issue occurs?
I assume you are talking about lenient unquoted strings / names, so something like this:
[ unquote-stringSPACE, next-value ]
(though I don't understand why the workaround would then help in this situation since apparently you are getting the JSON from something other than Gson)
Most helpful comment
@rmpt @hgschwibbe
Try this. It's fix for me
gson.fromJson(gson.toJson(<your_data>), YourClassName::class.java)