json-lib-user Mailing List for Json-lib (Page 10)
Brought to you by:
aalmiray
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(6) |
Sep
(5) |
Oct
(1) |
Nov
(7) |
Dec
(5) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(4) |
Feb
(5) |
Mar
(1) |
Apr
|
May
(11) |
Jun
(3) |
Jul
(12) |
Aug
(4) |
Sep
(8) |
Oct
(11) |
Nov
(7) |
Dec
(30) |
2008 |
Jan
(11) |
Feb
(15) |
Mar
(8) |
Apr
|
May
(9) |
Jun
(21) |
Jul
(1) |
Aug
(4) |
Sep
(1) |
Oct
|
Nov
(3) |
Dec
(8) |
2009 |
Jan
(6) |
Feb
(1) |
Mar
(3) |
Apr
(5) |
May
(10) |
Jun
(3) |
Jul
(1) |
Aug
|
Sep
(4) |
Oct
(1) |
Nov
(1) |
Dec
(1) |
2010 |
Jan
|
Feb
(2) |
Mar
(2) |
Apr
(3) |
May
(5) |
Jun
(1) |
Jul
|
Aug
(4) |
Sep
|
Oct
(1) |
Nov
(4) |
Dec
|
2011 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(8) |
Dec
|
2012 |
Jan
|
Feb
|
Mar
(4) |
Apr
|
May
(1) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2014 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Andres A. <aal...@ya...> - 2007-07-23 12:16:43
|
Dear Json-lib users, I'm pleased to announce that Json-lib version 2.0 has been released. There are many bug fixes and feature enhancements, most notably custom serialization, Groovy/JRuby support and enhanced xml processing. Many thanks to people that contributed bug reports, patches and tests. Feedback is always appreciated. Changelog:Added StringMetaClass for type conversionAdded ArrayListMetaClass for type conversionAdded HashMapMetaClass for type conversionAdded primitive support for JSONObject.accumulate()JSONObject.element() will not call accumulate() as it previously didRemoved duplicated code on JSONObject and JSONArrayRenamed JSONObject.putOpt to JSONObject.elementOptRenamed JSONObject.put to JSONObject.elementRenamed JSONArray.put to JSONArray.elementAdded assertNull and assertNotNull to JSONAssert1753528 Bean property of type String is transformed to JSONArray. Thanks to sckimos[at] gmail[dot]com 1751973 Make exceptions thrown by toBean() more explicit. Thanks to Oliver Zyngier1748029 Add JRuby support1747394 Support cycle detection in static builders1746838 JDK 1.4 compatibility. Thanks to Marcelo Liberato (provided a patch)1746272 JSONArray.put(long) not behaving properly for longs > 1L < < 62. Thanks to Mathias Herberst (provided a patch) 1739066 Error in Attributes conversion from xml to json in 2.0a21739247 Add readFromFile to XMLSerializer1728997 Add a JSONBuilder (like Grails)1728997 Add leftShift (Groovy) operator support1728993 Make JSONObject/JSONArray Comparable1683562 Support for preventing JavaScript Hijacking in web env1681775 Add SAX-like event support1715483 Skip transient field in a class1656299 Make JSONArray an implementation of java.util.List1656297 Make JSONObject an implementation of java.util.Map1636658 Add type handler support1656300 Add POGO support1694877 option to remove the double-quote around the property name1713184 JSONAssert accepts unequal JSONArrays, JSONObjects. Thanks to dcrosta[at] users[dot]sourceforge[dot] net (provided a patch)1719662 JSONUtils.stripQuotes generates an Exception. Thanks to Rodrigo Pantoni and Thomas Spiegl1693658 Optional space trimming when reading XML1693654 Optional removal of namespace prefixes when reading XML1693652 Skip namespaces when reading from XML Llama gratis a cualquier PC del mundo. Con una excelente calidad de sonido. http://mx.messenger.yahoo.com/ |
From: Andres A. <aal...@ya...> - 2007-07-13 14:24:05
|
Json-lib will try its best to transform any json-like literal into a JSONOb= ject or JSONArray,=0Abut in this case there is type information that must b= e taken into account and prevent that=0Atransformation. This is a bug, I'll= add it to the issue tracker.=0A=0AThanks for finding it!=0A=0ACheers,=0AAn= dres=0A =0A-------------------------------------------=0Ahttp://jroller.com= /page/aalmiray=0Ahttp://www.linkedin.com/in/aalmiray=0A--=0AWhat goes up, m= ust 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 u= nderstand recursion, we must first understand recursion.=0A=0A----- Mensaje= original ----=0ADe: =EA=B9=80=EC=9D=91=EC=88=98 <sc...@gm...>=0APara= : jso...@li...=0AEnviado: viernes, 13 de julio, 2007= 3:48:50=0AAsunto: [json-lib-user] Serializing "[]", "[12345]" problem=0A= =0AHi all~=0A=0AI'm using json-lib 1.1 jdk13 version.=0AI don't know why js= on-lib serializes "[]" or "[12345]" string to array type.=0A=0Atest code := =0A=0Apublic class JsonTest {=0A public static void main(String[] args) = throws Exception=0A=0A {=0A Test t =3D new Test();=0A t.se= tNickname("[12345]");=0A JSONObject obj =3D JSONObject.fromBean(t);= =0A System.out.println(obj.toString());=0A }=0A =0A public = static class Test {=0A=0A private String nickname;=0A=0A publ= ic String getNickname() {=0A return nickname;=0A }=0A=0A = public void setNickname(String name) {=0A this.nickname = =3D name;=0A=0A }=0A }=0A}=0A=0Athe result is :=0A{"nickname":[12= 345]}=0A=0AI expected that {"nickname":"[12345]"} would be printed.=0A=0A= Is there anyone who knows the reason?=0A=0A--------------------------------= -----------------------------------------=0AThis SF.net email is sponsored = by DB2 Express=0ADownload DB2 Express C - the FREE version of DB2 express a= nd take=0Acontrol of your XML. No limits. Just data. Click to get it now.= =0Ahttp://sourceforge.net/powerbar/db2/=0A_________________________________= ______________=0Ajson-lib-user mailing list=0Aj...@li...urcefor= ge.net=0Ahttps://lists.sourceforge.net/lists/listinfo/json-lib-user=0A=0A= =0A=0A=0A=0A=0A=0A ______________________________________________ =0AT= odo sobre la Copa Am=C3=A9rica.=0AMantenete actualizado con las =C3=BAltima= s noticias sobre esta competencia en Yahoo! Deportes. =C2=A1Ent=C3=A9rate p= rimero! http://mx.sports.yahoo.com/futbol/copaamerica/index.html |
From: <sc...@gm...> - 2007-07-13 08:48:57
|
Hi all~ I'm using json-lib 1.1 jdk13 version. I don't know why json-lib serializes "[]" or "[12345]" string to array type. test code : public class JsonTest { public static void main(String[] args) throws Exception { Test t = new Test(); t.setNickname("[12345]"); JSONObject obj = JSONObject.fromBean(t); System.out.println(obj.toString()); } public static class Test { private String nickname; public String getNickname() { return nickname; } public void setNickname(String name) { this.nickname = name; } } } the result is : {"nickname":[12345]} I expected that {"nickname":"[12345]"} would be printed. Is there anyone who knows the reason? |
From: Andres A. <aal...@ya...> - 2007-07-10 14:53:40
|
Dear Json-lib users,=0AThe next release (2.0) is almost ready, I'm still po= lishing some bits=0A(like the docs) and so far we have no more bugs to fix.= If you'd like=0Ato try the latest alpha release (2.0a3) you can grab a cop= y from =0A=0Ahttp://json-lib.sourceforge.net/m2/repo/snapshot/net/sf/json-l= ib/json-lib/2.0a3/=0A=0AFor those of you that may not have been up to date = with what's been happening=0Awith the next release you may find a list of w= hat's coming up at =0A=0Ahttp://jroller.com/page/aalmiray/?anchor=3Djson_li= b_features_for_2=0A=0AFeedback is always appreciated.=0A=0ACheers,=0AAndres= =0A =0A-------------------------------------------=0Ahttp://jroller.com/pag= e/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 under= stand recursion, we must first understand recursion.=0A=0A----- Mensaje ori= ginal ----=0ADe: Andres Almiray <aal...@ya...>=0APara: Petr V. <great= ma...@ya...>; jso...@li...=0AEnviado: jueves, 5= de julio, 2007 13:30:48=0AAsunto: Re: [json-lib-user] Json and POJO Conver= sion=0A=0AYour welcome Pter, in fact when transforming from JSON to Java no= t only do arrays will be=0Ahandled but arrays of primitives, muldimensional= arrays and collections.=0AJust call JSONSerializer.toJava() after properly= configuring targetClass and classMap (if needed)=0A=0AYou may find more in= fo at the project site.=0A=0ACheers,=0AAndres=0A =0A-----------------------= --------------------=0Ahttp://jroller.com/page/aalmiray=0Ahttp://www.linked= in.com/in/aalmiray=0A--=0AWhat goes up, must come down. Ask any system admi= nistrator.=0AThere are 10 types of people in the world: Those who understan= d binary, and those who don't.=0ATo understand recursion,=0A we must fi= rst understand recursion.=0A=0A----- Mensaje original ----=0ADe: Petr V. <g= rea...@ya...>=0APara: Andres Almiray <aal...@ya...>; json-lib= -u...@li...=0AEnviado: jueves, 5 de julio, 2007 13:13:42=0A= Asunto: Re: [json-lib-user] Json and POJO Conversion=0A=0AThanks Andres, yo= ur reply was very useful.=0A =0A I also found http://www.json.org/javadoc/o= rg/json/JSONObject.html#JSONObject(java.lang.Object,%20java.lang.String[])= =0A =0A but then I have to pass the attributes name of POJO object. =0A=0AI= will try the toJSON( ) method of JSONSerializer, would it be able to conve= rt the collections in POJO like arrays , maps, lists=0A etc??=0A=0AThanks a= lot once again, =0A=0APetr=0A=0AAndres Almiray <aal...@ya...> wrote:= Hi Petr,=0AI think you can find what you're looking for in net.sf.json.JSO= NSerializer=0AIt will let you serialize a Java bean, map, array, collection= into JSON and back, =0Ayou may specify a target class when converting back= to Java or leave it=0A blank,=0Athe result will be a DynaBean compatible w= ith jakarta's bean-utils.=0A =0ACheers,=0AAndres=0A=0A=0A------------------= -------------------------=0Ahttp://jroller.com/page/aalmiray=0Ahttp://www.l= inkedin.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 unde= rstand binary, and those who don't.=0ATo understand recursion, we must= first understand recursion.=0A=0A----- Mensaje original ----=0ADe: Petr V.= <gre...@ya...>=0APara: jso...@li...=0AEnvi= ado: jueves, 5 de julio, 2007=0A 12:46:43=0AAsunto:=0A [json-lib-user] Json= and POJO Conversion=0A=0AHi,=0A=0AI have some POJO Objects and I need to c= onvert them into JSON Objects and vice versa. Is there Any API that provide= s this functionality or I have to do manually conversion.=0A=0AI saw some s= ample code here =0A=0Ahttp://dev2dev.bea.com/pub/a/2007/02/introduction-jso= n.html=0A=0Awhere they are converting address book entry (POJO) into JSON o= bject manually and then converting it into String. The next question is tha= t can I make JSON object using that String again ?? Is there any efficient= way to convert pojo into json or vice versa, please let me know.=0A=0AThan= ks,=0A=0APetr V.=0A =0ASick sense of humor? Visit Yahoo! TV's Comed= y with an Edge to see=0A what's on, when.=0A ---------------------------= ----------------------------------------------=0AThis SF.net email is spons= ored by DB2 Express=0ADownload DB2 Express C - the FREE version of DB2 expr= ess and take=0Acontrol of your XML. No limits. Just data. Click to get it n= ow.=0Ahttp://sourceforge.net/powerbar/db2/=0A______________________________= _________________=0Ajson-lib-user mailing list=0Aj...@li...urce= forge.net=0Ahttps://lists.sourceforge.net/lists/listinfo/json-lib-user=0A= =0A=0A=0A=0A=0A=0A Do You Yahoo!? La mejor conexi=F3n a Internet y 2G= B extra a tu correo por $100 al mes. http://net.yahoo.com.mx =0A =0A = =0ABe a better Heartthrob. Get better relationship answers from someone who= knows.=0AYahoo! Answers - Check it out. =0A=0A=0A=0A=0A=0A=0A=09=09 =0ADo= You Yahoo!? =0ALa mejor conexi=F3n a Internet y 2GB extra a tu correo por = $100 al mes. http://net.yahoo.com.mx =0A-----------------------------------= --------------------------------------=0AThis SF.net email is sponsored by = DB2 Express=0ADownload DB2 Express C - the FREE version of DB2 express and = take=0Acontrol of your XML. No limits. Just data. Click to get it now.=0Aht= tp://sourceforge.net/powerbar/db2/=0A______________________________________= _________=0Ajson-lib-user mailing list=0Aj...@li...= t=0Ahttps://lists.sourceforge.net/lists/listinfo/json-lib-user=0A=0A=0A=0A= =0A=0A=0A=0A=09=0A=09=0A=09=09=0A__________________________________________= _________________ =0ADo You Yahoo!? =0ALa mejor conexi=F3n a Internet y <b = >2GB</b> extra a tu correo por $100 al mes. http://net.yahoo.com.mx =0A |
From: Andres A. <aal...@ya...> - 2007-07-05 18:30:56
|
Your welcome Pter, in fact when transforming from JSON to Java not only do = arrays will be=0Ahandled but arrays of primitives, muldimensional arrays an= d collections.=0AJust call JSONSerializer.toJava() after properly configuri= ng targetClass and classMap (if needed)=0A=0AYou may find more info at the = project site.=0A=0ACheers,=0AAndres=0A =0A---------------------------------= ----------=0Ahttp://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 understan= d recursion.=0A=0A----- Mensaje original ----=0ADe: Petr V. <greatman787@ya= hoo.com>=0APara: Andres Almiray <aal...@ya...>; json-lib-user@lists.s= ourceforge.net=0AEnviado: jueves, 5 de julio, 2007 13:13:42=0AAsunto: Re: [= json-lib-user] Json and POJO Conversion=0A=0AThanks Andres, your reply was = very useful.=0A =0A I also found http://www.json.org/javadoc/org/json/JSONO= bject.html#JSONObject(java.lang.Object,%20java.lang.String[])=0A =0A but th= en I have to pass the attributes name of POJO object. =0A=0AI will try the = toJSON( ) method of JSONSerializer, would it be able to convert the collect= ions in POJO like arrays , maps, lists etc??=0A=0AThanks a lot once again, = =0A=0APetr=0A=0AAndres Almiray <aal...@ya...> wrote: Hi Petr,=0AI thi= nk you can find what you're looking for in net.sf.json.JSONSerializer=0AIt = will let you serialize a Java bean, map, array, collection into JSON and ba= ck, =0Ayou may specify a target class when converting back to Java or leave= it=0A blank,=0Athe result will be a DynaBean compatible with jakarta's bea= n-utils.=0A =0ACheers,=0AAndres=0A=0A=0A-----------------------------------= --------=0Ahttp://jroller.com/page/aalmiray=0Ahttp://www.linkedin.com/in/aa= lmiray=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 understa= nd recursion.=0A=0A----- Mensaje original ----=0ADe: Petr V. <greatman787@y= ahoo.com>=0APara: jso...@li...=0AEnviado: jueves, 5 = de julio, 2007 12:46:43=0AAsunto:=0A [json-lib-user] Json and POJO Conversi= on=0A=0AHi,=0A=0AI have some POJO Objects and I need to convert them into J= SON Objects and vice versa. Is there Any API that provides this functionali= ty or I have to do manually conversion.=0A=0AI saw some sample code here = =0A=0Ahttp://dev2dev.bea.com/pub/a/2007/02/introduction-json.html=0A=0Awher= e they are converting address book entry (POJO) into JSON object manually a= nd then converting it into String. The next question is that can I make JSO= N object using that String again ?? Is there any efficient way to convert = pojo into json or vice versa, please let me know.=0A=0AThanks,=0A=0APetr V.= =0A =0ASick sense of humor? Visit Yahoo! TV's Comedy with an Edge t= o see what's on, when.=0A ----------------------------------------------= ---------------------------=0AThis SF.net email is sponsored by DB2 Express= =0ADownload DB2 Express C - the FREE version of DB2 express and take=0Acont= rol of your XML. No limits. Just data. Click to get it now.=0Ahttp://source= forge.net/powerbar/db2/=0A_______________________________________________= =0Ajson-lib-user mailing list=0Aj...@li...=0Ahttps= ://lists.sourceforge.net/lists/listinfo/json-lib-user=0A=0A=0A=0A=0A=0A=0A = Do You Yahoo!? La mejor conexi=F3n a Internet y 2GB extra a tu correo= por $100 al mes. http://net.yahoo.com.mx =0A =0A =0ABe a better Hear= tthrob. Get better relationship answers from someone who knows.=0AYahoo! An= swers - Check it out. =0A=0A=0A=0A=0A=0A=0A=09=0A=09=0A=09=09=0A___________= ________________________________________________ =0ADo You Yahoo!? =0ALa me= jor conexi=F3n a Internet y <b >2GB</b> extra a tu correo por $100 al mes. = http://net.yahoo.com.mx =0A |
From: Petr V. <gre...@ya...> - 2007-07-05 18:13:50
|
Thanks Andres, your reply was very useful. I also found http://www.json.org/javadoc/org/json/JSONObject.html#JSONObject(java.lang.Object,%20java.lang.String[]) but then I have to pass the attributes name of POJO object. I will try the toJSON( ) method of JSONSerializer, would it be able to convert the collections in POJO like arrays , maps, lists etc?? Thanks a lot once again, Petr Andres Almiray <aal...@ya...> wrote: Hi Petr, I think you can find what you're looking for in net.sf.json.JSONSerializer It will let you serialize a Java bean, map, array, collection into JSON and back, you may specify a target class when converting back to Java or leave it blank, the result will be a DynaBean compatible with jakarta's bean-utils. Cheers, Andres ------------------------------------------- http://jroller.com/page/aalmiray http://www.linkedin.com/in/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. ----- Mensaje original ---- De: Petr V. <gre...@ya...> Para: jso...@li... Enviado: jueves, 5 de julio, 2007 12:46:43 Asunto: [json-lib-user] Json and POJO Conversion Hi, I have some POJO Objects and I need to convert them into JSON Objects and vice versa. Is there Any API that provides this functionality or I have to do manually conversion. I saw some sample code here http://dev2dev.bea.com/pub/a/2007/02/introduction-json.html where they are converting address book entry (POJO) into JSON object manually and then converting it into String. The next question is that can I make JSON object using that String again ?? Is there any efficient way to convert pojo into json or vice versa, please let me know. Thanks, Petr V. --------------------------------- Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's on, when. ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ json-lib-user mailing list jso...@li... https://lists.sourceforge.net/lists/listinfo/json-lib-user --------------------------------- Do You Yahoo!? La mejor conexión a Internet y 2GB extra a tu correo por $100 al mes. http://net.yahoo.com.mx --------------------------------- Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out. |
From: Andres A. <aal...@ya...> - 2007-07-05 17:54:33
|
Florian, Using a map will work because maps do not carry type information for a property, only names and values =) Cheers, Andres ------------------------------------------- http://jroller.com/page/aalmiray http://www.linkedin.com/in/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. ----- Mensaje original ---- De: Florian Shkurti <flo...@gm...> Para: jso...@li... Enviado: jueves, 5 de julio, 2007 12:44:47 Asunto: Re: [json-lib-user] Default values when converting from Java beans to JSON objects Hi Andres, Here's a reply to myself :-) that might provide some sort of solution to the previous problem (although it is as elegant as an elephant) We can create a Map<Object, Object> that will contain all the names of the fields from the Java bean that we want to convert into a JSONObject associated to their values. Instead of converting the Java bean into a JSONObject we can convert the map. In fact both JSONObject.fromBean( map ) and JSONObject.fromMap( map ) seem to work as expected. I am not sure whether there are any subtle complications with this approach, but it seems to solve my problem (at least at the moment...) Thanks agin, Florian On 7/5/07, Florian Shkurti <flo...@gm...> wrote: Hi Andres, I have the following Java bean class: public class MyBean { private Integer myInt; private String myString; public MyBean(){ this.myInt = null; this.myString = null; } //getters & setters } When I try to convert this bean into a JSON object using JSONObject.fromBean( new MyBean() ) I get { "myInt": 0, "myString": "" } instead of what I would expect, namely { "myInt": null, "myString": null }. Is there a way to get the second JSONObject, which is what I intuitively expect? Thanks in advance, Florian ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ json-lib-user mailing list jso...@li... https://lists.sourceforge.net/lists/listinfo/json-lib-user Llama gratis a cualquier PC del mundo. Con una excelente calidad de sonido. http://mx.messenger.yahoo.com/ |
From: Andres A. <aal...@ya...> - 2007-07-05 17:53:26
|
Hi Petr,=0AI think you can find what you're looking for in net.sf.json.JSON= Serializer=0AIt will let you serialize a Java bean, map, array, collection = into JSON and back, =0Ayou may specify a target class when converting back = to Java or leave it blank,=0Athe result will be a DynaBean compatible with = jakarta's bean-utils.=0A =0ACheers,=0AAndres=0A=0A=0A----------------------= ---------------------=0Ahttp://jroller.com/page/aalmiray=0Ahttp://www.linke= din.com/in/aalmiray=0A--=0AWhat goes up, must come down. Ask any system adm= inistrator.=0AThere are 10 types of people in the world: Those who understa= nd binary, and those who don't.=0ATo understand recursion, we must firs= t understand recursion.=0A=0A----- Mensaje original ----=0ADe: Petr V. <gre= atm...@ya...>=0APara: jso...@li...=0AEnviado: = jueves, 5 de julio, 2007 12:46:43=0AAsunto: [json-lib-user] Json and POJO C= onversion=0A=0AHi,=0A=0AI have some POJO Objects and I need to convert them= into JSON Objects and vice versa. Is there Any API that provides this func= tionality or I have to do manually conversion.=0A=0AI saw some sample code = here =0A=0Ahttp://dev2dev.bea.com/pub/a/2007/02/introduction-json.html=0A= =0Awhere they are converting address book entry (POJO) into JSON object man= ually and then converting it into String. The next question is that can I m= ake JSON object using that String again ?? Is there any efficient way to co= nvert pojo into json or vice versa, please let me know.=0A=0AThanks,=0A=0AP= etr V.=0A =0A =0ASick sense of humor? Visit Yahoo! TV's =0AComedy with= an Edge to see what's on, when. =0A=0A=0A---------------------------------= ----------------------------------------=0AThis SF.net email is sponsored b= y DB2 Express=0ADownload DB2 Express C - the FREE version of DB2 express an= d take=0Acontrol of your XML. No limits. Just data. Click to get it now.=0A= http://sourceforge.net/powerbar/db2/=0A____________________________________= ___________=0Ajson-lib-user mailing list=0Aj...@li...urceforge.= net=0Ahttps://lists.sourceforge.net/lists/listinfo/json-lib-user=0A=0A=0A= =0A=0A=0A=0A=0A=09=0A=09=0A=09=09=0A_______________________________________= ____________________ =0ADo You Yahoo!? =0ALa mejor conexi=F3n a Internet y = <b >2GB</b> extra a tu correo por $100 al mes. http://net.yahoo.com.mx =0A |
From: Petr V. <gre...@ya...> - 2007-07-05 17:47:03
|
Hi, I have some POJO Objects and I need to convert them into JSON Objects and vice versa. Is there Any API that provides this functionality or I have to do manually conversion. I saw some sample code here http://dev2dev.bea.com/pub/a/2007/02/introduction-json.html where they are converting address book entry (POJO) into JSON object manually and then converting it into String. The next question is that can I make JSON object using that String again ?? Is there any efficient way to convert pojo into json or vice versa, please let me know. Thanks, Petr V. --------------------------------- Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's on, when. |
From: Florian S. <flo...@gm...> - 2007-07-05 17:44:48
|
Hi Andres, Here's a reply to myself :-) that might provide some sort of solution to the previous problem (although it is as elegant as an elephant) We can create a Map<Object, Object> that will contain all the names of the fields from the Java bean that we want to convert into a JSONObject associated to their values. Instead of converting the Java bean into a JSONObject we can convert the map. In fact both JSONObject.fromBean( map ) and JSONObject.fromMap( map ) seem to work as expected. I am not sure whether there are any subtle complications with this approach, but it seems to solve my problem (at least at the moment...) Thanks agin, Florian On 7/5/07, Florian Shkurti <flo...@gm...> wrote: > > Hi Andres, > > I have the following Java bean class: > > public class MyBean { > > private Integer myInt; > > private String myString; > > public MyBean(){ > this.myInt = null; > this.myString = null; > } > > //getters & setters > } > > > When I try to convert this bean into a JSON object using > JSONObject.fromBean( new MyBean() ) > > I get { "myInt": 0, "myString": "" } instead of what I would > expect, namely { "myInt": null, "myString": null }. > > Is there a way to get the second JSONObject, which is > what I intuitively expect? > > Thanks in advance, > Florian > > > > > > |
From: Andres A. <aal...@ya...> - 2007-07-05 15:35:43
|
Hi Florian, Per the JSON spec,only objects may be null, meaning that numbers, booleans, arrays and strings will use a default value when the Java bean has a null reference assigned. Default values are Number - integer 0 Boolean - false String - empty "" Array (Collection) - empty [ ] As you say in your message, you expect 'myInt' and 'myString' to have a null value (which is the correct assumption on the Java world) but when serializing to JSON those properties are submitted to the above rules. You can "fool" the serialization though, by making the following changes to your bean: public class MyBean { private Object myInt; private Object myString; public Object getMyInt(){ return myInt; } public Object getMyString(){ return myString; } public void setMyInt( Integer myInt ) { this.myInt = myInt; } public void setMyString( String myString ) { this.myString = myString; } } Which will allow you to transform the bean to JSON but won0t work the other way around as the write methods for each property do not exist 'perse' because the types for read/write are not equal, the PropertyDescriptor will see the properties as read-only. If you add the proper setters with Object then the properties will become writable, allowing for the following test to run green: public void testBean() { NBean bean = new NBean(); JSONObject json = JSONObject.fromObject( bean ); System.err.println( json ); bean.setMyInt( new Integer( 1 ) ); json = JSONObject.fromObject( bean ); System.err.println( json ); NBean b = (NBean) JSONObject.toBean( JSONObject.fromObject( "{'myInt':null}" ), NBean.class ); System.err.println( b ); b = (NBean) JSONObject.toBean( JSONObject.fromObject( "{'myInt':42}" ), NBean.class ); System.err.println( b ); b = (NBean) JSONObject.toBean( JSONObject.fromObject( "{'myInt':'48'}" ), NBean.class ); System.err.println( b ); } -- output {"myInt":null,"myString":null} {"myInt":1,"myString":null} [null,null] [42,null] [48,null] The problem with allowing the workaround is that if you send {"myInt":null,"myString":null} across the wire to a browser and if it uses the json parser [or the defualt eval()] 'myInt' and 'myString' will be treated as null object references instead of empty scalar values for number and string. Cheers, Andres ------------------------------------------- http://jroller.com/page/aalmiray http://www.linkedin.com/in/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. ----- Mensaje original ---- De: Florian Shkurti <flo...@gm...> Para: jso...@li... Enviado: jueves, 5 de julio, 2007 10:07:11 Asunto: [json-lib-user] Default values when converting from Java beans to JSON objects Hi Andres, I have the following Java bean class: public class MyBean { private Integer myInt; private String myString; public MyBean(){ this.myInt = null; this.myString = null; } //getters & setters } When I try to convert this bean into a JSON object using JSONObject.fromBean( new MyBean() ) I get { "myInt": 0, "myString": "" } instead of what I would expect, namely { "myInt": null, "myString": null }. Is there a way to get the second JSONObject, which is what I intuitively expect? Thanks in advance, Florian ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ json-lib-user mailing list jso...@li... https://lists.sourceforge.net/lists/listinfo/json-lib-user Llama gratis a cualquier PC del mundo. Con una excelente calidad de sonido. http://mx.messenger.yahoo.com/ |
From: Florian S. <flo...@gm...> - 2007-07-05 15:07:12
|
Hi Andres, I have the following Java bean class: public class MyBean { private Integer myInt; private String myString; public MyBean(){ this.myInt = null; this.myString = null; } //getters & setters } When I try to convert this bean into a JSON object using JSONObject.fromBean( new MyBean() ) I get { "myInt": 0, "myString": "" } instead of what I would expect, namely { "myInt": null, "myString": null }. Is there a way to get the second JSONObject, which is what I intuitively expect? Thanks in advance, Florian |
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 |
From: Andres A. <aal...@ya...> - 2007-06-07 14:26:47
|
Hi guys, Just to let you know that Json-lib 2.0a2 is available at http://json-lib.sourceforge.net/m2/repo/snapshot/ It includes a couple of bug fixes, more tests and better Groovy integration. The code is available at the cvs. Feedback is always appreciated. Cheers, Andres ------------------------------------------- http://jroller.com/page/aalmiray http://www.linkedin.com/in/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. ----- Mensaje original ---- De: Andres Almiray <aal...@ya...> Para: jso...@li... Enviado: martes, 22 de mayo, 2007 18:28:18 Asunto: [json-lib-user] [ANN] Json-lib 2.0a1 is available Hi guys, Just to let you know that Json-lib 2.0a1 is available at http://json-lib.sourceforge.net/m2/repo/snapshot/ It includes a couple of bug fixes and the most asked feature: custom serialization. More details at http://jroller.com/page/aalmiray/?anchor=json_lib_2_0a1_is The javadocs are not complete and the code is not yet on the cvs. Feedback is always appreciated. Cheers ------------------------------------------- http://jroller.com/page/aalmiray http://www.linkedin.com/in/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. Llama gratis a cualquier PC del mundo. Con una excelente calidad de sonido. Yahoo! Messenger------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ json-lib-user mailing list jso...@li... https://lists.sourceforge.net/lists/listinfo/json-lib-user Llama gratis a cualquier PC del mundo. Con una excelente calidad de sonido. http://mx.messenger.yahoo.com/ |
From: Florian S. <flo...@gm...> - 2007-06-06 19:02:03
|
Hi Andres, The following question might have an obvious answer, but I'd like to ask it anyway. Suppose I have this Java Bean: public class MyBean implements java.io.Serializable{ private Integer length; private static Integer staticLength; //getters and setters for both fields } and I use JSONObject.fromBean( new MyBean() ).toString() to get its JSON string representation, in which case I get {"length":0} Why is staticLength not included in the JSON string? Thanks, Florian PS: I am in the process of exploring the capabilities of json-lib, so I'll try to post some good questions in this mailing list, and hopefully that will make it easier for people to get familiar with the library. |
From: Andres A. <aal...@ya...> - 2007-05-29 15:59:59
|
Florian,=0AGenerics support is not in the roadmap (yet) but your example s= howed a potential flaw=0Ain the code that transforms a JSONObject into a be= an, the keys 'file1.java' and 'file2.java'=0Awill be transformed using the = configured JavaIdentifierTransformer and perhaps that is not=0Awhat you'll = want in sometimes, so I've added a new config setting to skip transformatio= n=0Aof keys that will be added to a map.=0A=0AKeep those questions coming!= =0A=0ACheers,=0AAndres=0A=0A-------------------------------------------=0Ah= ttp://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: lunes, 28 d= e mayo, 2007 10:40:08=0AAsunto: [json-lib-user] Converting JSON strings to = Java Maps=0A=0AHi all,=0A=0AI have a question regarding the conversion of J= SON string=0Ainto Java objects. Please bare with me, as I have already =0Ar= ead json-lib's documentation, without being able to find =0Aanswers to all = of my questions. =0A=0A=0AConsider the following JSON string:=0A=0A{"commen= ts": {"file1.java" : [{ "pos_start": 34, "pos_end": 45}],=0A = "file2.java" : [{ "pos_start": 56, "pos_end": 78}] }}=0A=0A=0A= =0AI need to convert this string into a Java object. Ideally, I would=0Alik= e to obtain an object of the class=0A=0Apublic class MyBean{=0A =0A = private Map<String, List<Map<String, Integer>>> comments;=0A=0A=0A //= getters & setters=0A =0A}=0A=0AAny advice on how I could do that? = =0AIf not, can I avoid specifying a bean class with fields "file1.java"=0Aa= nd "file2.java" ? =0A=0A=0AThanks in advance,=0AFlorian=0A=0A=0A=0A=0A=0A--= -----------------------------------------------------------------------=0AT= his SF.net email is sponsored by DB2 Express=0ADownload DB2 Express C - the= FREE version of DB2 express and take=0Acontrol of your XML. No limits. Jus= t data. Click to get it now.=0Ahttp://sourceforge.net/powerbar/db2/=0A_____= __________________________________________=0Ajson-lib-user mailing list=0Aj= son...@li...=0Ahttps://lists.sourceforge.net/lists/li= stinfo/json-lib-user=0A=0A=0A=0A=0A=0A=0A=0A _________________________= _____________________ =0A=A1As=F3mbrate! Conoce el Beta de Correo Yahoo! qu= e incluye muchas herramientas que har=E1n tu vida m=E1s sencilla.=0Ahttp://= correo.yahoo.com.mx/ |
From: Andres A. <aal...@ya...> - 2007-05-28 15:44:04
|
Florian,=0AThe exception is caused by PropertyUtils.setProperty as it parse= s the property name=0Asearching for nested properties (with '.') or mapped/= indexed ones (with '[ ]').=0AJson-lib does not supports nested properties, = but you can alter the name of the target=0Aproperty when transforming from = JSON to Java using a JavaIdentifierTransformer strategy=0A(this does not c= hange the key name on your JSONObject, just the target).=0AThere are 5 defa= ult strategies:=0ANOOP - performs no transformation (default)=0ASTRICT - al= ways throws JSONException if the name is not a valid JavaIdentifier=0ACAMEL= _CASE - transforms the name into camelCase, non-javaIdentifiers are treated= as word boundaries=0AWHITESPACE - chops all whitesspace and non-javaIdenti= fiers from the name=0AUNDERSCORE - chops all '_' and non-javaIdentifiers fr= om the name=0A=0AYou may register a different strategy with JSONUtils.setJa= vaIdentifierTransformer (I think I'm moving that=0Ato JsonConfig as it is n= ow the central place for configuration how parsing should behave).=0A=0AChe= ers,=0AAndres=0A =0A-------------------------------------------=0Ahttp://jr= oller.com/page/aalmiray=0Ahttp://www.linkedin.com/in/aalmiray=0A--=0AWhat g= oes 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 <flo...@gm...>= =0APara: jso...@li...=0AEnviado: lunes, 28 de mayo, = 2007 10:22:49=0AAsunto: [json-lib-user] Problem with special characters in = JSON string keys=0A=0AHi all,=0A=0AI am facing the following problem while = using json-lib:=0A=0A{"array" : [1,2] } =0A=0AWhen I try to convert this JS= ON string into a Java=0Aobject, I get no errors at all; everything works fi= ne.=0A=0AHowever, trying to convert this JSON string =0A=0A{"array.java" : = [1,2]}=0A=0A=0Ainto a Java object yields an error:=0A=0AException in thread= "main" net.sf.json.JSONException: =0Ajava.lang.NoSuchMethodException=0A: = =0AUnknown property 'array'=0A at net.sf.json.JSONObject.toBean(JSONObje= ct.java:543)=0A=0ACaused by: java.lang.NoSuchMethodException: =0AUnknown pr= operty 'array'=0A at org.apache.commons.beanutils=0A=0A .P= ropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1112)=0A at or= g.apache.commons.beanutils=0A .PropertyUtilsBean.setNestedPro= perty(PropertyUtilsBean.java:1619)=0A at org.apache.commons.beanutils=0A= =0A .PropertyUtilsBean.setProperty(PropertyUtilsBean.java:167= 7)=0A at org.apache.commons.beanutils=0A .PropertyUtils.se= tProperty(PropertyUtils.java:559)=0A at net.sf.json.JSONObject.setProper= ty=0A(JSONObject.java:781)=0A at net.sf.json.JSONObject.setProperty(JSON= Object.java:761)=0A at net.sf.json.JSONObject.toBean(JSONObject.java:518= )=0A=0A=0A=0AIt seems that keys that contain period cannot be fully =0A=0Ap= arsed; only the string up to the first period is taken into account.=0AAny = ideas why?=0A=0AThanks in advance,=0AFlorian=0A=0A-------------------------= ------------------------------------------------=0AThis SF.net email is spo= nsored by DB2 Express=0ADownload DB2 Express C - the FREE version of DB2 ex= press and take=0Acontrol of your XML. No limits. Just data. Click to get it= now.=0Ahttp://sourceforge.net/powerbar/db2/=0A____________________________= ___________________=0Ajson-lib-user mailing list=0Aj...@li...ur= ceforge.net=0Ahttps://lists.sourceforge.net/lists/listinfo/json-lib-user=0A= =0A=0A=0A=0A=0A=0A=0A ______________________________________________ = =0A=A1As=F3mbrate! Conoce el Beta de Correo Yahoo! que incluye muchas herra= mientas que har=E1n tu vida m=E1s sencilla.=0Ahttp://correo.yahoo.com.mx/ |
From: Florian S. <flo...@gm...> - 2007-05-28 15:40:13
|
Hi all, I have a question regarding the conversion of JSON string into Java objects. Please bare with me, as I have already read json-lib's documentation, without being able to find answers to all of my questions. Consider the following JSON string: {"comments": {"file1.java" : [{ "pos_start": 34, "pos_end": 45}], "file2.java" : [{ "pos_start": 56, "pos_end": 78}] }} I need to convert this string into a Java object. Ideally, I would like to obtain an object of the class public class MyBean{ private Map<String, List<Map<String, Integer>>> comments; //getters & setters } Any advice on how I could do that? If not, can I avoid specifying a bean class with fields "file1.java" and "file2.java" ? Thanks in advance, Florian |
From: Florian S. <flo...@gm...> - 2007-05-28 15:22:55
|
Hi all, I am facing the following problem while using json-lib: {"array" : [1,2] } When I try to convert this JSON string into a Java object, I get no errors at all; everything works fine. However, trying to convert this JSON string {"array.java" : [1,2]} into a Java object yields an error: Exception in thread "main" net.sf.json.JSONException: java.lang.NoSuchMethodException: Unknown property 'array' at net.sf.json.JSONObject.toBean(JSONObject.java:543) Caused by: java.lang.NoSuchMethodException: Unknown property 'array' at org.apache.commons.beanutils .PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java :1112) at org.apache.commons.beanutils .PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java :1619) at org.apache.commons.beanutils .PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1677) at org.apache.commons.beanutils .PropertyUtils.setProperty(PropertyUtils.java:559) at net.sf.json.JSONObject.setProperty(JSONObject.java:781) at net.sf.json.JSONObject.setProperty(JSONObject.java:761) at net.sf.json.JSONObject.toBean(JSONObject.java:518) It seems that keys that contain period cannot be fully parsed; only the string up to the first period is taken into account. Any ideas why? Thanks in advance, Florian |
From: Andres A. <aal...@ya...> - 2007-05-22 23:28:36
|
Hi guys, Just to let you know that Json-lib 2.0a1 is available at http://json-lib.sourceforge.net/m2/repo/snapshot/ It includes a couple of bug fixes and the most asked feature: custom serialization. More details at http://jroller.com/page/aalmiray/?anchor=json_lib_2_0a1_is The javadocs are not complete and the code is not yet on the cvs. Feedback is always appreciated. Cheers ------------------------------------------- http://jroller.com/page/aalmiray http://www.linkedin.com/in/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. Llama gratis a cualquier PC del mundo. Con una excelente calidad de sonido. http://mx.messenger.yahoo.com/ |
From: Andres A. <aal...@ya...> - 2007-05-15 22:46:52
|
Hi Rodrigo,=0A=0AYou found a bug on JSONUtils.stripQuotes ! (it generated t= he index exception in an untested case)=0A=0Aand now it has been solved.=0A= =0AAbout the 'o's and 'e's, they're the default names for object and array = elements when none are provided,=0A=0Ayou can change them by calling setObj= ectName() and setElementName() on the serializer.=0A=0A=0A=0ACheers,=0A=0AA= ndres =0A-------------------------------------------=0Ahttp://jroller.com/p= age/aalmiray=0Ahttp://www.linkedin.com/in/aalmiray=0A--=0AWhat goes up, mus= t come down. Ask any system administrator.=0AThere are 10 types of people i= n the world: Those who understand binary, and those who don't.=0ATo und= erstand recursion, we must first understand recursion.=0A=0A----- Mensaje o= riginal ----=0ADe: Rodrigo Pantoni <rod...@ya...>=0APara: j= son...@li...=0AEnviado: viernes, 11 de mayo, 2007 9:2= 3:40=0AAsunto: [json-lib-user] problems regarding Json-lib - convert a big = XML in the Json format and after, recover the original XML file=0A=0AHello = guys,=0A I got a problem using Json-lib, and I would =0Alike to check wi= th you if there is somethink that I can do to solve =0Athat.=0A=0A =0A=0A = I have tryed to convert a big XML in the Json =0Aformat and after, recove= r the original XML file. I know that the released =0Aversion 1.1 of Json li= b does not do this because a lot of information of XML is =0Alost. Then, I = get a current development snapshot of (1.2-SNAPSHOT) to test it. =0AIt real= ly works, but with some bugs. Some XML elements are not with the right =0An= ame, the most of them have a name like "o" or "e". =0A=0A =0A=0A The jav= a code, the original XML, the Json file =0Aand the generated XML file is at= tached to this email (ok.zip).=0A=0A =0A=0A =0A=0A I get other problem t= oo (run time bug), related =0Ato the message:=0A=0A "Exception in thread "m= ain" =0Anet.sf.json.JSONException: java.lang.StringIndexOutOfBoundsExceptio= n: String =0Aindex out of range: -1=0A at =0Anet.sf.json.xml.XMLSeri= alizer.read(XMLSerializer.java:307)"=0A=0A =0A=0AThe used xml is attached i= n runtimebug.zip.=0A=0A =0A=0A =0A=0ACheers,=0A=0ARodrigo=0A=0A=0A=0A=0A=0A= =0A__________________________________________________=0AFale com seus amigo= s de gra=E7a com o novo Yahoo! Messenger =0Ahttp://br.messenger.yahoo.com/= -------------------------------------------------------------------------= =0AThis SF.net email is sponsored by DB2 Express=0ADownload DB2 Express C -= the FREE version of DB2 express and take=0Acontrol of your 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.sourceforge.net/list= s/listinfo/json-lib-user=0A=0A=0A=0A=0A=0A=0A=0A Llama gratis a cualqu= ier PC del mundo. =0ACon una excelente calidad de sonido. =0Ahttp://mx.mess= enger.yahoo.com/ |
From: Andres A. <aal...@ya...> - 2007-05-15 21:46:49
|
Hi Jiro,=0AThe answer lies in the type you are using for your property, whi= ch I'm assuming=0Aits String. Because the JSON spec forbids null to be assi= gned to a String, an=0Aempty one is used if null value is encountered. The = following types allow null=0Ato be assigned as you expect: Object, Map, and= any bean class. =0A=0AExample:=0Aclass MyBean {=0A private Object anO= bject;=0A private String anString;=0A // getters & setters=0A}=0A= =0AMyBean bean =3D new MyBean();=0AJSON json =3D JSONObject.fromObject( bea= n );=0ASystem.err.println( json.toString( 2 ) );=0A=0Aprints:=0A{=0A "anSt= ring": "",=0A "anObject": null=0A}=0A =0ACheers,=0AAndres=0A=0A-----------= --------------------------------=0Ahttp://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 w= ho understand binary, and those who don't.=0ATo understand recursion, w= e must first understand recursion.=0A=0A----- Mensaje original ----=0ADe: J= iro Iwamoto <iw...@sy...>=0APara: jso...@li...urc= eforge.net=0AEnviado: lunes, 14 de mayo, 2007 3:12:57=0AAsunto: [json-lib-u= ser] JSONObject.fromBean(bean) cannot describe null=0A=0AHello.=0A=0AI inte= nd to transform bean into json using JSONObject.fromBean(bean).=0AThe prope= rty of bean include null value like below=0A=0Abean.setHoge(null);=0A=0AI e= xpect json below=0A{"hoge": null}=0A=0Abut result is=0A{"hoge": ""}=0A=0Ais= this bug?=0A=0APlease teach it.=0A=0AJiro=0A=0A-- =0AJiro Iwamoto <iwamoto= @sysrdc.ns-sol.co.jp>=0A=0A------------------------------------------------= -------------------------=0AThis SF.net email is sponsored by DB2 Express= =0ADownload DB2 Express C - the FREE version of DB2 express and take=0Acont= rol of your XML. No limits. Just data. Click to get it now.=0Ahttp://source= forge.net/powerbar/db2/=0A_______________________________________________= =0Ajson-lib-user mailing list=0Aj...@li...=0Ahttps= ://lists.sourceforge.net/lists/listinfo/json-lib-user=0A=0A=0A=0A=0A=0A=0A= =0A=09=0A=09=0A=09=09=0A___________________________________________________= ________ =0ADo You Yahoo!? =0ALa mejor conexi=F3n a Internet y <b >2GB</b> = extra a tu correo por $100 al mes. http://net.yahoo.com.mx =0A |
From: Jiro I. <iw...@sy...> - 2007-05-14 08:13:11
|
Hello. I intend to transform bean into json using JSONObject.fromBean(bean). The property of bean include null value like below bean.setHoge(null); I expect json below {"hoge": null} but result is {"hoge": ""} is this bug? Please teach it. Jiro -- Jiro Iwamoto <iw...@sy...> |
From: Ben A. <tw....@gm...> - 2007-05-01 18:56:30
|
well, here's the simple implementation I put in one of my utility classes (THIS IS UNTESTED): public static Object dot(JSONObject jo, String notation) { Object o =3D null; try { String[] tokens =3D notation.split("."); for (int i=3D0; i<(tokens.length-1); i++) { jo =3D jo.optJSONObject(tokens[i]); } o =3D jo.opt(tokens[tokens.length-1]); } catch (Exception e) { // do nothing } return o; On 5/1/07, Andres Almiray <aal...@ya...> wrote: > > Ben, > At this time there is no such thing in Json-lib, but it surely is a cool > idea. > If you can submit a patch for it it would be great =3D) > As an alternative you may switch to Groovy and do something like the > following > > value =3D jsonObject?.schedules?.'2008'?.weeks[1]?.victory > > Cheers, > Andres > ------------------------------------------- > 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. > > ----- Mensaje original ---- > De: Ben Anderson <tw....@gm...> > Para: jso...@li... > Enviado: martes, 1 de mayo, 2007 9:04:08 > Asunto: [json-lib-user] use dot notation implemented anywhere? > > Hi, > Is there anything like this? > > Boolean v =3D (Boolean) JSONUtils.getValue(jsonObject, " > schedules.2008.weeks.1.victory"); > > It'd be nice if I could do this and not have to check for nulls each > time. For instance, I've been doing this: > > Date d =3D null; > try { > jsonObject.optJSONObject > ("schedules").optJSONObject.("2008").optJSONObject("weeks").optJSONObject= ("1").optBoolean("victory"); > } catch (Exception e) { > // do nothing > } > > Any ideas? If not, I might write my own simple little util that pretty > much does the above. > > Thanks, > Ben Anderson > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > json-lib-user mailing list > jso...@li... > https://lists.sourceforge.net/lists/listinfo/json-lib-user > > > __________________________________________________ > Correo Yahoo! > Espacio para todos tus mensajes, antivirus y antispam =A1gratis! > Reg=EDstrate ya - http://correo.yahoo.com.mx/ > |
From: Ben A. <tw....@gm...> - 2007-05-01 14:04:10
|
Hi, Is there anything like this? Boolean v = (Boolean) JSONUtils.getValue(jsonObject, " schedules.2008.weeks.1.victory"); It'd be nice if I could do this and not have to check for nulls each time. For instance, I've been doing this: Date d = null; try { jsonObject.optJSONObject ("schedules").optJSONObject.("2008").optJSONObject("weeks").optJSONObject("1").optBoolean("victory"); } catch (Exception e) { // do nothing } Any ideas? If not, I might write my own simple little util that pretty much does the above. Thanks, Ben Anderson |