Re: [json-lib-user] fromBean - field order
Brought to you by:
aalmiray
From: Andres A. <aal...@ya...> - 2006-08-16 14:02:22
|
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ászló <las...@we...> escribió: > Hi, > > > > Im using the JSONObject.fromBean() method and i > notified, that as the > JSON specification in an object the lib messes up > the declared field > order. > > Its 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 abc order. > > > > 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 > dont want to reinvent the wheel. > > > > Thanks, Lazlo > ------------------------------------------- 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 ¡gratis! Regístrate ya - http://correo.yahoo.com.mx/ |