Re: [json-lib-user] Convert collection of beans to json
Brought to you by:
aalmiray
From: Andres A. <aal...@ya...> - 2008-08-13 16:35:06
|
Vadim, You can't transform a Collection into a JSONObject. Collections and arrays can only be transformed into JSONArray Regards, Andres ------------------------------------------- http://jroller.com/aalmiray http://www.linkedin.com/in/aalmiray -- What goes up, must come down. Ask any system administrator. There are 10 types of people in the world: Those who understand binary, and those who don't. To understand recursion, we must first understand recursion. ----- Original Message ---- From: Vadim <dea...@gm...> To: jso...@li... Sent: Wednesday, August 13, 2008 2:47:54 AM Subject: [json-lib-user] Convert collection of beans to json Hello, I've been trying to solve this for couple of hours now. I need to transform Collection<Vehicle> to JSONObject, where Vehicle (id = 1, regNr = 2) -> JSONObject.toString() == "{'id':'1', 'regNr':'2'}" {Vehicle (id = 1, regNr = 2), Vehicle (id = 2, regNr = 6)} -> JSONObject.toString() == "{'id':'1,2', 'regNr':'2,6'}" (not "{'id':'1', 'regNr':'2'}, {'id':'2', 'regNr':'6'}") JSONSerializer.fromObject(Collection) returns an array of separate objects transformed to JSON ("{'id':'1', 'regNr':'2'}, {'id':'2', 'regNr':'6'}"). Of course I could do the needed transformation by hand, but I'm sure there's something in the API that I'm missing. |