Re: [json-lib-user] Should static fields of a bean be included in its JSON representation?
Brought to you by:
aalmiray
From: Andres A. <aal...@ya...> - 2007-06-07 15:10:52
|
Florian,=0AThe static "property" is not picked up by PropertyDescriptors, b= ecause=0Aproperties belong to a bean (an instance), in your case the static= =0Aproperty belongs to a class (a bean type). It may seem like a good idea= =0Aat first to support static properties but let's look at the following ex= ample,=0Aa basic implementation of the Singleton pattern:=0A=0Aclass MySing= letonBean {=0A private static MyBean instance =3D new MyBean();=0A priv= ate MyBean(){ ... }=0A public static MyBean getInstance(){ return instanc= e; }=0A ...=0A}=0A=0AIn order to avoid the 'instance' property to be seri= alized (causing an endless=0Aloop) you'll have to register it in the exclus= ions, the same will happen with all=0Aother 'property-like' static methods = that you wish to leave out of the serialization=0Aprocess. Depending on the= available static methods of a bean, you may end=0Awith lost of exclusions.= =0A=0ACheers,=0AAndres=0A =0A-------------------------------------------=0A= http://jroller.com/page/aalmiray=0Ahttp://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: Those who understand binary, and those who= don't.=0ATo understand recursion, we must first understand recursion.= =0A=0A----- Mensaje original ----=0ADe: Florian Shkurti <florian.shkurti@gm= ail.com>=0APara: jso...@li...=0AEnviado: mi=E9rcoles= , 6 de junio, 2007 14:02:02=0AAsunto: [json-lib-user] Should static fields = of a bean be included in its JSON representation?=0A=0AHi Andres,=0A=0AThe = following question might have an obvious answer, but=0AI'd like to ask it a= nyway. Suppose I have this Java Bean:=0A=0Apublic class MyBean implements j= ava.io.Serializable{=0A=0A private Integer length;=0A=0A = private static Integer staticLength;=0A=0A=0A //getters and set= ters for both fields=0A} =0A=0A=0Aand I use JSONObject.fromBean( new MyBean= () ).toString() to=0Aget its JSON string representation, in which case I ge= t=0A=0A=0A{"length":0}=0A=0AWhy is staticLength not included in the JSON st= ring?=0A=0A=0AThanks,=0AFlorian =0A=0A=0APS: I am in the process of exp= loring the capabilities of =0A json-lib, so I'll try to post some goo= d questions in =0A=0A this mailing list, and hopefully that will make= it =0A easier for people to get familiar with the library. =0A = =0A =0A=0A =0A=0A--------------------------------------------------------= -----------------=0AThis SF.net email is sponsored by DB2 Express=0ADownloa= d DB2 Express C - the FREE version of DB2 express and take=0Acontrol of you= r XML. No limits. Just data. Click to get it now.=0Ahttp://sourceforge.net/= powerbar/db2/=0A_______________________________________________=0Ajson-lib-= user mailing list=0Aj...@li...=0Ahttps://lists.sou= rceforge.net/lists/listinfo/json-lib-user=0A=0A=0A=0A=0A=0A=0A=0A=09=0A=09= =0A=09=09=0A___________________________________________________________ =0A= Do You Yahoo!? =0ALa mejor conexi=F3n a Internet y <b >2GB</b> extra a tu c= orreo por $100 al mes. http://net.yahoo.com.mx =0A |