My application is using camel rest (2.15.2) to catch a POST json String and then uses jettison to convert to a JSON Object. It is working fine with normal request.
POST request: {"request"={"lname"="aaa", "fname"="bb"}}
1. String body = exchange.getIn().getBody(String.class);
2. JSONObject obj = new JSONObject(body);
When i debug, variable body = {request={lname=aaa, fname=bb}}
.
And line 2 returns a JSONObject. so far so good
if we try to another the request:
{"request"={"lname"=" ", "fname"="aa"}}
then body = {request={lname= , fname=aa}}
line2 returns Exception.
Could you please help me to fix this issue: convert json string which contains element has empty value string to json object.
The above request is acceptable in my scenarios.
Error:
org.codehaus.jettison.json.JSONException: Missing value. at character 15 of {request={lname= , fname=aa}} at org.codehaus.jettison.json.JSONTokener.syntaxError(JSONTokener.java:463) at org.codehaus.jettison.json.JSONTokener.nextValue(JSONTokener.java:356) at org.codehaus.jettison.json.JSONObject.(JSONObject.java:230) at org.codehaus.jettison.json.JSONTokener.newJSONObject(JSONTokener.java:412) at org.codehaus.jettison.json.JSONTokener.nextValue(JSONTokener.java:327) at org.codehaus.jettison.json.JSONObject.(JSONObject.java:230) at org.codehaus.jettison.json.JSONObject.(JSONObject.java:311)