Thread: Re: [json-lib-user] Problem with conversion of BigDecimal to JSON text
Brought to you by:
aalmiray
From: Rashmi D. <ra...@gm...> - 2006-11-29 07:53:26
Attachments:
JSONUtils.java
|
Hi, We have made changes to JSONUtils.java and now BigDecimal is working. Can you please review the changes and let us know what you think? Regards ~Rashmi -----Original Message----- From: Rashmi Dixit [mailto:ra...@gm...] Sent: Wednesday, November 29, 2006 12:21 PM To: 'jso...@li...' Subject: Problem with conversion of BigDecimal to JSON text Hi, We are using JSON-lib 0.9 to convert our beans to JSON format before sending the response. Our bean uses many BigDecimal fields. We tried the following: JSONObject.fromBean(new BigDecimal(10)); This throws the following exception: Caused by: java.lang.NoSuchMethodException: Property 'scale' has no getter method at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(Propert yUtilsBean.java:1127) at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(Propert yUtilsBean.java:686) at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtils Bean.java:715) at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.jav a:290) at net.sf.json.JSONObject.fromBean(JSONObject.java:161) The apache commons searches for getter setter methods for each member variable - which is not present for this class. Even the fromObject method throws a similar exception. The JSON utils function isNumber does not identify BigDecimal as a number. This causes problems here. We have too many BigDecimal fields in our bean and so would rather not move to any other data type. Can you help us here please? We are completely stuck. Regards ~Rashmi |
From: Andres A. <aal...@ya...> - 2006-11-29 16:17:12
|
Hi Rashmi,=0A=0AYour changes seem to be ok, but if I think BigInteger shoul= d be supported as well.=0AThis feature already has been requested as "JSONA= rray fails to convert an array of BigDecimals"=0Ahttp://sourceforge.net/tra= cker/index.php?func=3Ddetail&aid=3D1596168&group_id=3D171425&atid=3D857928= =0A=0AThe code is already on the cvs and includes an update on ezmorph-0.9.= 1 =0A(hint: BigIntegerMorpher and BigDecimalMorpher). The release of ezmorp= h will be in a couple of hours,=0Aafter that you may download the latest sn= apshot from json-lib's cvs.=0A =0ACheers.=0A=0A=0A-------------------------= ------------------=0AIng. Andres Almiray Jaramillo=0Ahttp://jroller.com/pag= e/aalmiray=0A--=0AWhat goes up, must come down. Ask any system administrato= r.=0AThere are 10 types of people in the world: Those who understand binary= , and those who don't.=0ATo understand recursion, we must first understand = recursion.=0A=0A----- Original Message ----=0AFrom: Rashmi Dixit <rashmid@g= mail.com>=0ATo: jso...@li...=0ASent: Wednesday, Nove= mber 29, 2006 1:53:17 AM=0ASubject: Re: [json-lib-user] Problem with conver= sion of BigDecimal to JSON text=0A=0AHi,=0A=0AWe have made changes to JSONU= tils.java and now BigDecimal is working.=0ACan you please review the change= s and let us know what you think?=0A=0ARegards=0A~Rashmi=0A=0A-----Original= Message-----=0AFrom: Rashmi Dixit [mailto:ra...@gm...] =0ASent: Wedn= esday, November 29, 2006 12:21 PM=0ATo: 'jso...@li...= t'=0ASubject: Problem with conversion of BigDecimal to JSON text=0A=0AHi,= =0A=0AWe are using JSON-lib 0.9 to convert our beans to JSON format before= =0Asending the response. Our bean uses many BigDecimal fields. We tried the= =0Afollowing:=0A=0AJSONObject.fromBean(new BigDecimal(10));=0A=0AThis throw= s the following exception:=0A=0ACaused by: java.lang.NoSuchMethodException:= Property 'scale' has no=0Agetter method=0Aat=0Aorg.apache.commons.beanutil= s.PropertyUtilsBean.getSimpleProperty(Propert=0AyUtilsBean.java:1127)=0Aat= =0Aorg.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(Propert= =0AyUtilsBean.java:686)=0Aat=0Aorg.apache.commons.beanutils.PropertyUtilsBe= an.getProperty(PropertyUtils=0ABean.java:715)=0Aat=0Aorg.apache.commons.bea= nutils.PropertyUtils.getProperty(PropertyUtils.jav=0Aa:290)=0Aat net.sf.jso= n.JSONObject.fromBean(JSONObject.java:161)=0A=0AThe apache commons searches= for getter setter methods for each member=0Avariable - which is not presen= t for this class.=0A=0AEven the fromObject method throws a similar exceptio= n. The JSON utils=0Afunction isNumber does not identify BigDecimal as a num= ber. This causes=0Aproblems here.=0A=0AWe have too many BigDecimal fields i= n our bean and so would rather not=0Amove to any other data type. Can you h= elp us here please? We are=0Acompletely stuck. =0A=0ARegards=0A~Rashmi=0A= =0A------------------------------------------------------------------------= -=0ATake Surveys. Earn Cash. Influence the Future of IT=0AJoin SourceForge.= net's Techsay panel and you'll get the chance to share your=0Aopinions on I= T & business topics through brief surveys - and earn cash=0Ahttp://www.tech= say.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3DDEVDEV=0A________= _______________________________________=0Ajson-lib-user mailing list=0Ajson= -li...@li...=0Ahttps://lists.sourceforge.net/lists/listi= nfo/json-lib-user=0A=0A=0A=0A=0A=0A=0A=0A=09=0A=09=0A=09=09=0A_____________= ______________________________________________ =0ADo You Yahoo!? =0ALa mejo= r conexi=F3n a Internet y <b >2GB</b> extra a tu correo por $100 al mes. ht= tp://net.yahoo.com.mx =0A |