Reputation: 205
val jsonObject = new org.json.JSONObject("{\"name\":\"abc\",\"Estd date\":\"23.06.1995\",\"GrowthRate\":50%}")
println(jsonObject)
new ObjectMapper().readTree("{\"name\":\"abc\",\"Estd date\":\"23.06.1995\",\"GrowthRate\":50%}")
Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Unexpected character ('%' (code 37)): was expecting comma to separate OBJECT entries
What can be done to have the same behavior as that of JSONObject? We have some restrictions due to which we cannot use JSONObject. Any help with this?
Is there a way we can do this using custom serializer? Currency symbols like $50 should also be parsed.
I am using jackson-databind-2.6.7.1.jar
Upvotes: 1
Views: 351
Reputation: 9588
Expressions like 50%
or 10$
must be transported as string [1].
new ObjectMapper().readTree("{\"name\":\"abc\",\"Estd date\":\"23.06.1995\",\"GrowthRate\":\"50%\"}")
will work.
[1]
A JSON value MUST be an object, array, number, or string, or one of the following three literal names: false null true
https://www.rfc-editor.org/rfc/rfc7159#page-5
Related:
Upvotes: 1