Re: [json-lib-user] Problem converting to JSONArray to byte array
Brought to you by:
aalmiray
From: Andres A. <aal...@ya...> - 2007-10-13 04:53:23
|
Hi Jeev,=0A=0AIt looks like a bug, I tried all number combinations and both= byte and short failed, I'll see to it.=0A=0ACheers,=0AAndres=0A =0A-------= ------------------------------------=0Ahttp://jroller.com/page/aalmiray=0Ah= ttp://www.linkedin.com/in/aalmiray=0A--=0AWhat goes up, must come down. Ask= any system administrator.=0AThere are 10 types of people in the world: Tho= se who understand binary, and those who don't.=0ATo understand recursio= n, we must first understand recursion.=0A=0A----- Original Message ----=0AF= rom: Jeevandra Sivarajah <jee...@ho...>=0ATo: json-lib-user@lists= .sourceforge.net=0ASent: Friday, October 12, 2007 9:20:13 PM=0ASubject: [js= on-lib-user] Problem converting to JSONArray to byte array=0A=0A=0A=0A=0A.h= mmessage P=0A{=0Amargin:0px;padding:0px;}=0Abody.hmmessage=0A{=0AFONT-SIZE:= 10pt;FONT-FAMILY:Tahoma;}=0A=0AHi,=0AI am having problem converting JSONArr= ay to a byte array. I've used the following code in my program to process a= rrays in my bean. It seems to work fine for other primitive types but byte.= Is there a reason for this? Many thanks for your advice.=0A=0Ajeev=0A=0A= =0AIt returns=0A=0A=0Ajava.lang.IllegalArgumentException: argument type mis= match=0A at java.lang.reflect.Array.set(Native Method)=0A at = net.sf.json.JSONArray.toArray(JSONArray.java:273)=0A at net.sf.json.= JSONArray.toArray(JSONArray.java:225)=0A at spar.utility.JSONBeanPro= cessor.processArrays(JSONBeanProcessor.java:53)=0A at spar.utility.J= SONBeanProcessor.getBean(JSONBeanProcessor.java:31)=0A at spar.testi= ng.JSONTestRun.main(JSONTestRun.java:51)=0A=0A=0A=0A=0Aprivate static void = processArrays(Object bean, Class beanClass, JSONObject object){=0A = =0A Field[] fields =3D beanClass.getDeclaredFields();=0A = for (Field field : fields) {=0A field.setAccessible(true);= =0A if(object.containsKey(field.getName())){=0A = Object memberobject =3Dobject.get(field.getName());=0A = if(JSONUtils.isArray(memberobject) && field.getType().isArray()){=0A = =0A try {=0A = JSONArray array =3D JSONArray.fromObject(memberobject);=0A = =0A //Problem with the following!=0A=0A=0A = field.set(bean, field.getType().cast(JSONArray.toArr= ay(array, field.getType().getComponentType())));=0A } ca= tch (IllegalArgumentException ex) {=0A Logger.getLog= ger(JSONBeanProcessor.class.getName()).log(Level.SEVERE, null, ex);=0A = } catch (IllegalAccessException ex) {=0A = Logger.getLogger(JSONBeanProcessor.class.getName()).log(Level.SEVERE, n= ull, ex);=0A }=0A =0A = }//end if=0A =0A }//end if=0A = =0A }=0A }=0A=0A=0A=0A=0A=0A"If a man does not ke= ep pace with his companions, perhaps it is because he hears a different dru= mmer. Let him step to the music which he hears, however measured or far awa= y."=0A=0AH.D Thoreau=0A=0AGet your free suite of Windows Live services! Win= dows Live=0A=0A=0A=0A=0A=0A =0A______________________________________= ______________________________________________=0APinpoint customers who are= looking for what you sell. =0Ahttp://searchmarketing.yahoo.com/ |