parispurchase / json-io

Automatically exported from code.google.com/p/json-io
0 stars 0 forks source link

cloneObject(String s) #15

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
public Object cloneObject(Object root)
{
    return JsonReader.jsonToJava(JsonWriter.objectToJson(root));    
}
2. cloneObject("Hello.")
3.  Input is invalid JSON; does not start with '{' or '[', c=34

What is the expected output? What do you see instead?
"Hello."

What version of the product are you using? On what operating system?
2.4.5

Please provide any additional information below.

Original issue reported on code.google.com by chq...@gmail.com on 13 Feb 2014 at 10:50

GoogleCodeExporter commented 9 years ago
I have the same problem - a String will be serialized fine as simple String:
String strJson = JsonWriter.objectToJson("5");
 =>  "5"

But the json reader can not read this vice versa, it throws an Exception
String strClone = (String) JsonReader.jsonToJava(strJson);

Same Exception when formatting the string with
String strBeauty = JsonWriter.formatJson(strJson);

java.io.IOException: Input is invalid JSON; does not start with '{' or '[', c=34
Last read: "
line: 1, col: 2
    at com.cedarsoftware.util.io.JsonReader.error(JsonReader.java:3203)
    at com.cedarsoftware.util.io.JsonReader.readJsonObject(JsonReader.java:2213)
    at com.cedarsoftware.util.io.JsonReader.readObject(JsonReader.java:1161)
    at com.cedarsoftware.util.io.JsonReader.jsonToJava(JsonReader.java:1085)

Thus, we have to make a workaround for serializing/deserializing simple 
Strings. We are using json-io 2.6.1. We would be pleased if this could be 
fixed! Thanks a lot for this fine piece of work.

Original comment by christia...@gmail.com on 8 Jul 2014 at 8:41