1
 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

H.Aadhithya
  • 205
  • 1
  • 12

1 Answers1

1

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:

Community
  • 1
  • 1
jschnasse
  • 8,526
  • 6
  • 32
  • 72
  • Yes, I am not sure how JSONObject parses it by default as a string. Is there any configuration by default which treats these values by default as a string ? – H.Aadhithya Aug 27 '20 at 06:49
  • I don't know. Maybe ask this as a new question?! I think I would preprocess the not-Json with some regexp/string-replace. At the same time I would ask the producer to provide valid Json. – jschnasse Aug 27 '20 at 07:03