java - Jackson writeValueAsString: valid JSON not valid anymore -


i have strings, want create valid json.

input: timestamp, feature, id, data (is valid json itself)

{"items":[{"id":"13123545","count": 5, "amount": 11.6},{"id": "1638343", "count": 1, "amount": 55.99}], "oid": 5556}

    //some code here     valueitems.add(new valueitem(timestamp, feature, id, data));     valuedata.setinformation(valueitems);     valuestring = valuemapper.writevalueasstring(valuedata);     system.out.println(valuestring); 

output:

{     "information": [         {             "timestamp": "2013-01-01",             "feature": "login",             "id": 0,             "data": "{\"items\":[{\"id\":\"14737\",\"count\": 5, \"amount\": 11.6},{\"id\": \"1874345\", \"count\": 1, \"amount\": 55.99}], \"oid\": 5556}"         }     ] } 

the json valid, element of "data" not valid json anymore due . why happen? how can change or prevent this?

the problem because representing json text string, , quotes escaped (i.e. \").

why representing json in way, internally in java program? generally, makes more sense maintain pure-pojo internal representation , translate of json in 1 go, rather mixing pojos , json.

in case, mean data field in information class should not string, should instead object defined containing set<item> items , long oid, or similar.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -