Re: [json-lib-user] fromBean - field order
Brought to you by:
aalmiray
From: <las...@we...> - 2006-08-16 18:34:44
|
Hi, I made a solution, but not with PropertyDescriptors, but with standard reflection. My question is that how can I turn on the order using = PropertyDescriptors? My solution is perfect for me, I'm just curios. (Other thing is that you = are prefering 3rd party lib instead of java core because of the = compatibility with former java versions?) Lazlo -----Eredeti =FCzenet----- Felad=F3: Andres Almiray [mailto:aal...@ya...]=20 K=FCldve: 2006. augusztus 16. 16:02 C=EDmzett: Fogas L=E1szl=F3; jso...@li... T=E1rgy: Re: [json-lib-user] fromBean - field order Hi Lazlo, You are correct, according to the spec: "An object is an unordered set of name/value pairs." Its possible to change the lib and let it keep record of the insertion order, but it wont be using LinkedHashMap, as that class was introduced in JDK 1.4. Two solutions are available: a) use commons.collection's LinkedMap b) home grown Map that preservers order insertion For option a) a new dependency must be introduced. For option b) the DRY concept applies. Once the storage is solved, we can turn on the order of which PropertyDescriptors are obtained. --- Fogas L=E1szl=F3 <las...@we...> escribi=F3: > Hi, >=20 > =20 >=20 > I=92m using the JSONObject.fromBean() method and i > notified, that =96 as the > JSON specification =96 in an object the lib messes up > the declared field > order. >=20 > It=92s ok for the spec, but not for me. I modded the > code (use LinkedHashMap > instead of simple HashMap to take care of the field > order) The filed order > in the json text now almost the same as in my bean, > but my problem is, that > the common beanutils propertydescriptor stores the > fields in =84abc=94 order.=20 >=20 > =20 >=20 > Is there any ready solution for my purpose, or i > should change the way that > jsonlib uses reflection. Because > class.getDeclaredFields(); method gives > back the declared field order. But if there any > working solution now, I > don=92t want to reinvent the wheel. >=20 > =20 >=20 > Thanks, Lazlo >=20 ------------------------------------------- Ing. Andres Almiray Jaramillo http://jroller.com/page/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. __________________________________________________ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam =A1gratis!=20 Reg=EDstrate ya - http://correo.yahoo.com.mx/=20 |