json-lib-user Mailing List for Json-lib (Page 9)
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: Yuen C. L. <yue...@gm...> - 2007-11-07 20:11:46
|
Hi Arashi, Have you tried using backslash, e.g. '\{'? That should work. On Nov 7, 2007 11:32 PM, Arash Amiri <ara...@re...> wrote: > Hi > I have a (I guess simple) question: > > I have a JSONString in Java such as > > String jsonString = "{ 'fields': [ > {name: 'Firstname{{}}',value: '{{{Tom}}}',attributes: [],}, > {name: 'Lastname',value: 'Meier',attributes: [],}, > {name: 'Knows',value: 'Frec',attributes: [{ name: 'Since', value: > '2000' }],}, > {name: 'Knows',value: 'Kim',attributes: [{ name: 'Since', value: > '2003' }],}, > {name: 'Knows',value: 'Mark',attributes: [{ name: 'Since', value: > '2002' }, > { name: 'From', value: 'Reports' }]} > ]}" > > When I use JSONObject jsonForm = new JSONObject(jsonString); > > I get an Exception: > > net.sf.json.JSONException: Expected a ':' after a key at character 7 > of {{{Tom}}} > > I dont get this. The braces are inside quotes, there should not be a > problem, or??? > > please help > greetings, arash > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > json-lib-user mailing list > jso...@li... > https://lists.sourceforge.net/lists/listinfo/json-lib-user > -- Cheers, Yuen-Chi Lian "I do not seek; I find." - Pablo Picasso |
From: Arash A. <ara...@re...> - 2007-11-07 15:32:49
|
Hi I have a (I guess simple) question: I have a JSONString in Java such as String jsonString = "{ 'fields': [ {name: 'Firstname{{}}',value: '{{{Tom}}}',attributes: [],}, {name: 'Lastname',value: 'Meier',attributes: [],}, {name: 'Knows',value: 'Frec',attributes: [{ name: 'Since', value: '2000' }],}, {name: 'Knows',value: 'Kim',attributes: [{ name: 'Since', value: '2003' }],}, {name: 'Knows',value: 'Mark',attributes: [{ name: 'Since', value: '2002' }, { name: 'From', value: 'Reports' }]} ]}" When I use JSONObject jsonForm = new JSONObject(jsonString); I get an Exception: net.sf.json.JSONException: Expected a ':' after a key at character 7 of {{{Tom}}} I dont get this. The braces are inside quotes, there should not be a problem, or??? please help greetings, arash |
From: Andres A. <aal...@ya...> - 2007-10-24 15:57:19
|
Hi John,=0A=0AIt looks to me that your code should throw a different except= ion because each book is no a Book per-se unless=0Aa) change brackets to cu= rly braces=0Ab) add an explicit "cast" to Book with the as keyword=0A=0AThe= following samples should work=0A=0Adef books1 =3D builder.books {=0A boo= k =3D {title: "The Definitive Guide to Grails", author: "Graeme Rocher"}=0A= book =3D {title: "The Definitive Guide to Grails", author: "Graeme Roche= r"}=0A}=0A=0Adef books1 =3D builder.books {=0A book =3D [title: "The Defi= nitive Guide to Grails", author: "Graeme Rocher"] as Book=0A book =3D [ti= tle: "The Definitive Guide to Grails", author: "Graeme Rocher"] as Book=0A}= =0A =0ACheers,=0AAndres=0A=0A=0A-------------------------------------------= =0Ahttp://jroller.com/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----- Original Message ----=0AFrom: John D <j0h...@ya...>=0ATo= : jso...@li...=0ASent: Tuesday, October 23, 2007 2:5= 0:35 PM=0ASubject: [json-lib-user] Groovy Usage=0A=0A=0AHi,=0A=0AI'm trying= to use json-lib from groovy for the first time and am unable to get even t= he simplest example to execute. Here's what I have:=0A=0A<john:scripts >gro= ovy -v=0AGroovy Version: 1.1-rc-1 JVM: 1.5.0_07-87=0A=0A<john:scripts >cat = test_json.groovy =0Aimport net.sf.json.groovy.JsonGroovyBuilder=0A=0Adef bu= ilder =3D new JsonGroovyBuilder()=0Adef books1 =3D builder.books {=0A boo= k =3D [title: "The Definitive Guide to Grails", author: "Graeme Rocher"]=0A= book =3D [title: "The Definitive Guide to Grails", author: "Graeme Roche= r"]=0A}=0Aprintln books1=0A=0A=0A<john:scripts >groovy test_json.groovy =0A= Caught: net.sf.json.JSONException: null object=0A at=0A test_json.ru= n(test_json.groovy:8)=0A at test_json.main(test_json.groovy)=0A=0A= =0AAny ideas, am I doing something stupid?=0A=0AThanks,=0A=0AJohn=0A=0A=0A= =0A=0A=0A=0A=0A=0A__________________________________________________=0ADo Y= ou Yahoo!?=0ATired of spam? Yahoo! Mail has the best spam protection aroun= d =0Ahttp://mail.yahoo.com |
From: John D <j0h...@ya...> - 2007-10-23 19:50:43
|
Hi,=0A=0AI'm trying to use json-lib from groovy for the first time and am u= nable to get even the simplest example to execute. Here's what I have:=0A= =0A<john:scripts >groovy -v=0AGroovy Version: 1.1-rc-1 JVM: 1.5.0_07-87=0A= =0A<john:scripts >cat test_json.groovy =0Aimport net.sf.json.groovy.JsonGro= ovyBuilder=0A=0Adef builder =3D new JsonGroovyBuilder()=0Adef books1 =3D bu= ilder.books {=0A book =3D [title: "The Definitive Guide to Grails", autho= r: "Graeme Rocher"]=0A book =3D [title: "The Definitive Guide to Grails",= author: "Graeme Rocher"]=0A}=0Aprintln books1=0A=0A=0A<john:scripts >groov= y test_json.groovy =0ACaught: net.sf.json.JSONException: null object=0A = at test_json.run(test_json.groovy:8)=0A at test_json.main(test_j= son.groovy)=0A=0A=0AAny ideas, am I doing something stupid?=0A=0AThanks,=0A= =0AJohn=0A=0A=0A |
From: Yuen C. L. <yue...@gm...> - 2007-10-16 15:59:14
|
Thanks a lot Andres. All these while, I downloaded the artifact, renamed it and manually installed it, argh! On 10/16/07, Andres Almiray <aal...@ya...> wrote: > > Hi John, > > You'll have to add a <classifier> tag like so: > > <dependency> > <groupId>net.sf.json-lib</groupId> > <artifactId>json-lib</artifactId> > <version>2.1</version> > <classifier>jdk5</classifier> > </dependency> > > 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. > > ----- Original Message ---- > From: John Cartwright <Joh...@no...> > To: jso...@li... > Sent: Tuesday, October 16, 2007 9:46:51 AM > Subject: [json-lib-user] using json-lib in maven dependency > > Hello All, > > I'm having a little trouble getting json-lib to work w/ my maven2 > project. Trying to use a dependency like: > > <dependency> > <groupId>net.sf.json-lib</groupId> > <artifactId>json-lib</artifactId> > <version>2.1</version> > </dependency> > > I think the problem lies between the mismatch of the artifactId, > "json-lib-2.1-jdk15.jar > < > http://repo1.maven.org/maven2/net/sf/json-lib/json-lib/2.1/json-lib-2.1-jdk15.jar>" > > and the pom, "json-lib-2.1.pom > < > http://repo1.maven.org/maven2/net/sf/json-lib/json-lib/2.1/json-lib-2.1.pom>". > > Any advice on how to deal w/ this or would it be appropriate to upload a > jar file that matches the pom? > > Thanks! > > -- john > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > json-lib-user mailing list > jso...@li... > https://lists.sourceforge.net/lists/listinfo/json-lib-user > > > ------------------------------ > Looking for a deal? Find great prices on flights and hotels<http://us.rd.yahoo.com/evt=47094/*http://farechase.yahoo.com/;_ylc=X3oDMTFicDJoNDllBF9TAzk3NDA3NTg5BHBvcwMxMwRzZWMDZ3JvdXBzBHNsawNlbWFpbC1uY20->with Yahoo! FareChase. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > json-lib-user mailing list > jso...@li... > https://lists.sourceforge.net/lists/listinfo/json-lib-user > > -- Cheers, Yuen-Chi Lian "I do not seek; I find." - Pablo Picasso |
From: John C. <Joh...@no...> - 2007-10-16 15:21:29
|
Thanks for your prompt reply Andres - adding a classifier of "jdk15" works perfectly! -- john Andres Almiray wrote: > Hi John, > > You'll have to add a <classifier> tag like so: > > <dependency> > <groupId>net.sf.json-lib</groupId> > <artifactId>json-lib</artifactId> > <version>2.1</version> > <classifier>jdk5</classifier> > </dependency> > > 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. > > > ----- Original Message ---- > From: John Cartwright <Joh...@no...> > To: jso...@li... > Sent: Tuesday, October 16, 2007 9:46:51 AM > Subject: [json-lib-user] using json-lib in maven dependency > > Hello All, > > I'm having a little trouble getting json-lib to work w/ my maven2 > project. Trying to use a dependency like: > > <dependency> > <groupId>net.sf.json-lib</groupId> > <artifactId>json-lib</artifactId> > <version>2.1</version> > </dependency> > > I think the problem lies between the mismatch of the artifactId, > "json-lib-2.1-jdk15.jar > <http://repo1.maven.org/maven2/net/sf/json-lib/json-lib/2.1/json-lib-2.1-jdk15.jar>" > > and the pom, "json-lib-2.1.pom > <http://repo1.maven.org/maven2/net/sf/json-lib/json-lib/2.1/json-lib-2.1.pom>". > > Any advice on how to deal w/ this or would it be appropriate to upload a > jar file that matches the pom? > > Thanks! > > -- john > > > ------------------------------------------------------------------------- > This SF.net <http://SF.net> email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > json-lib-user mailing list > jso...@li... > <mailto:jso...@li...> > https://lists.sourceforge.net/lists/listinfo/json-lib-user > > > ------------------------------------------------------------------------ > Looking for a deal? Find great prices on flights and hotels > <http://us.rd.yahoo.com/evt=47094/*http://farechase.yahoo.com/;_ylc=X3oDMTFicDJoNDllBF9TAzk3NDA3NTg5BHBvcwMxMwRzZWMDZ3JvdXBzBHNsawNlbWFpbC1uY20-> > with Yahoo! FareChase. |
From: Andres A. <aal...@ya...> - 2007-10-16 15:15:00
|
Hi John,=0A=0AYou'll have to add a <classifier> tag like so:=0A=0A<dependen= cy>=0A <groupId>net.sf.json-lib</groupId>=0A <artifactId>json= -lib</artifactId>=0A <version>2.1</version>=0A <classifier>jd= k5</classifier>=0A</dependency>=0A=0ACheers,=0AAndres=0A =0A---------------= ----------------------------=0Ahttp://jroller.com/page/aalmiray=0Ahttp://ww= w.linkedin.com/in/aalmiray=0A--=0AWhat goes up, must come down. Ask any sys= tem administrator.=0AThere are 10 types of people in the world: Those who u= nderstand binary, and those who don't.=0ATo understand recursion, we mu= st first understand recursion.=0A=0A----- Original Message ----=0AFrom: Joh= n Cartwright <Joh...@no...>=0ATo: jso...@li...urcef= orge.net=0ASent: Tuesday, October 16, 2007 9:46:51 AM=0ASubject: [json-lib-= user] using json-lib in maven dependency=0A=0A=0AHello All,=0A=0AI'm having= a little trouble getting json-lib to work w/ my maven2 =0Aproject. Trying= to use a dependency like:=0A=0A<dependency>=0A <groupId>net.sf.json= -lib</groupId>=0A <artifactId>json-lib</artifactId>=0A <versi= on>2.1</version>=0A</dependency>=0A=0AI think the problem lies between the = mismatch of the artifactId, =0A"json-lib-2.1-jdk15.jar =0A<http://repo1.mav= en.org/maven2/net/sf/json-lib/json-lib/2.1/json-lib-2.1-jdk15.jar>" =0Aand = the pom, "json-lib-2.1.pom =0A<http://repo1.maven.org/maven2/net/sf/json-li= b/json-lib/2.1/json-lib-2.1.pom>". =0AAny advice on how to deal w/ this or= would it be appropriate to upload=0A a =0Ajar file that matches the pom?= =0A=0AThanks!=0A=0A-- john=0A=0A=0A----------------------------------------= ---------------------------------=0AThis SF.net email is sponsored by: Splu= nk Inc.=0AStill grepping through log files to find problems? Stop.=0ANow S= earch log events and configuration files using AJAX and a browser.=0ADownlo= ad your FREE copy of Splunk now >> http://get.splunk.com/=0A_______________= ________________________________=0Ajson-lib-user mailing list=0Ajson-lib-us= er...@li...=0Ahttps://lists.sourceforge.net/lists/listinfo/jso= n-lib-user=0A=0A=0A=0A=0A=0A=0A ______________________________________= ______________________________________________=0ATonight's top picks. What = will you watch tonight? Preview the hottest shows on Yahoo! TV.=0Ahttp://tv= .yahoo.com/ =0A |
From: John C. <Joh...@no...> - 2007-10-16 14:46:59
|
Hello All, I'm having a little trouble getting json-lib to work w/ my maven2 project. Trying to use a dependency like: <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.1</version> </dependency> I think the problem lies between the mismatch of the artifactId, "json-lib-2.1-jdk15.jar <http://repo1.maven.org/maven2/net/sf/json-lib/json-lib/2.1/json-lib-2.1-jdk15.jar>" and the pom, "json-lib-2.1.pom <http://repo1.maven.org/maven2/net/sf/json-lib/json-lib/2.1/json-lib-2.1.pom>". Any advice on how to deal w/ this or would it be appropriate to upload a jar file that matches the pom? Thanks! -- john |
From: Andres A. <aal...@ya...> - 2007-10-15 04:08:42
|
Hi John,=0A=0ASorry for the late reply. The answer is yes and no, let me ex= plain. XMLSerializer has an option to expose a value's type when serializin= g JSON to XML, that information is written as an attribute named 'type'. Wh= en reading it is assumed you want to recover that information if 'type' is = an attribute of a node, but it seems that in your case type has a business = meaning and should be treated like that instead of a construct of the libra= ry. The same will happen with an attributed named 'class' by the way.=0A = =0ALet me look for an alternative that is backward compatible at the same t= ime.=0A=0ACheers,=0AAndres=0A=0A=0A----------------------------------------= ---=0Ahttp://jroller.com/page/aalmiray=0Ahttp://www.linkedin.com/in/aalmira= y=0A--=0AWhat goes up, must come down. Ask any system administrator.=0ATher= e are 10 types of people in the world: Those who understand binary, and tho= se who don't.=0ATo understand recursion, we must first understand recur= sion.=0A=0A----- Original Message ----=0AFrom: John Cartwright <John.C.Cart= wr...@no...>=0ATo: jso...@li...=0ASent: Monday, = October 8, 2007 10:29:37 AM=0ASubject: [json-lib-user] XML -> JSON, "type" = attribute omitted?=0A=0AHello All,=0A=0AIt seems to me that when converting= XML to JSON, elements w/ an =0Aattribute named "type" have that attribute = omitted. Is this expected =0Abehavior?=0A=0AThanks!=0A=0A-- john=0A=0A=0A-= ------------------------------------------------------------------------=0A= This SF.net email is sponsored by: Splunk Inc.=0AStill grepping through log= files to find problems? Stop.=0ANow Search log events and configuration f= iles using AJAX and a browser.=0ADownload your FREE copy of Splunk now >> h= ttp://get.splunk.com/=0A_______________________________________________=0Aj= son-lib-user mailing list=0Aj...@li...=0Ahttps://l= ists.sourceforge.net/lists/listinfo/json-lib-user=0A=0A=0A=0A=0A=0A=0A=0A = =0A___________________________________________________________________= _________________=0ABoardwalk for $500? In 2007? Ha! Play Monopoly Here and= Now (it's updated for today's economy) at Yahoo! Games.=0Ahttp://get.games= .yahoo.com/proddesc?gamekey=3Dmonopolyherenow |
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/ |
From: Jeevandra S. <jee...@ho...> - 2007-10-13 02:20:23
|
Hi, I am having problem converting JSONArray to a byte array. I've used the fol= lowing code in my program to process arrays in my bean. It seems to work fi= ne for other primitive types but byte. Is there a reason for this? Many tha= nks for your advice. jeev It returns java.lang.IllegalArgumentException: argument type mismatch at java.lang.reflect.Array.set(Native Method) at net.sf.json.JSONArray.toArray(JSONArray.java:273) at net.sf.json.JSONArray.toArray(JSONArray.java:225) at spar.utility.JSONBeanProcessor.processArrays(JSONBeanProcessor.j= ava:53) at spar.utility.JSONBeanProcessor.getBean(JSONBeanProcessor.java:31= ) at spar.testing.JSONTestRun.main(JSONTestRun.java:51) private static void processArrays(Object bean, Class beanClass, JSONObject = object){ =20 Field[] fields =3D beanClass.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); if(object.containsKey(field.getName())){ Object memberobject =3Dobject.get(field.getName()); if(JSONUtils.isArray(memberobject) && field.getType().i= sArray()){ =20 try { JSONArray array =3D JSONArray.fromObject(memberobje= ct); =20 //Problem with the following! field.set(bean, field.getType().cast(JSONArray.toAr= ray(array, field.getType().getComponentType()))); } catch (IllegalArgumentException ex) { Logger.getLogger(JSONBeanProcessor.class.getName())= .log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(JSONBeanProcessor.class.getName())= .log(Level.SEVERE, null, ex); } =20 }//end if =20 }//end if =20 } } "If a man does not keep pace with his companions, perhaps it is because he = hears a different drummer. Let him step to the music which he hears, howeve= r measured or far away."=0A= =0A= H.D Thoreau _________________________________________________________________ Publish your photos to your Space easily with Photo Gallery http://www.get.live.com/wl/all= |
From: John C. <Joh...@no...> - 2007-10-08 15:29:47
|
Hello All, It seems to me that when converting XML to JSON, elements w/ an attribute named "type" have that attribute omitted. Is this expected behavior? Thanks! -- john |
From: Andres A. <aal...@ya...> - 2007-10-06 03:18:45
|
Hi everybody,=0A=0AI've been giving some though to the following idea: supp= ort serialization through annotations, like Flexjson does. The reason to go= forward is that some may feel more comfortable with this type of serializa= tion, the reason to not do it is that so far Json-lib provides a non-intrus= ive serialization mechanism (not counting JSONString).=0A=0AI'd love to hea= r what's your take on this matter.=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 wh= o understand binary, and those who don't.=0ATo understand recursion, we= must first understand recursion.=0A=0A=0A ___________________________= _________________________________________________________=0A=A1S=E9 un mejo= r asador!=0AAprende todo sobre asados. =0Ahttp://mx.ya= hoo.com/promos/mejorasador.html |
From: Yuen C. L. <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YW4KPgo+ICJJIGRvIG5vdCBz ZWVrOyBJIGZpbmQuIiAtIFBhYmxvIFBpY2Fzc28KPgo+Cj4gLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tCj4KPiDCoVPDqSB1biBtZWpvciBhbWJpZW50YWxpc3RhIQo+IEVuY3VlbnRyYSBj b25zZWpvcyBwYXJhIGN1aWRhciBlbCBsdWdhciBkb25kZSB2aXZpbW9zIGVuOgo+IGh0dHA6Ly9t eC55YWhvby5jb20vcHJvbW9zL21lam9yYW1iaWVudGFsaXN0YS5odG1sCj4KCgoKLS0gCkNoZWVy cywKWXVlbi1DaGkgTGlhbgoKIkkgZG8gbm90IHNlZWs7IEkgZmluZC4iIC0gUGFibG8gUGljYXNz bwo= |
From: Andres A. <aal...@ya...> - 2007-09-29 15:24:15
|
Hi Lian,=0A=0AIt seems to me that you are using Json-lib 2.0, which has a b= ug when serializing back to Java and the bean has an array property of non-= primitive type. It has been fixed for 2.1-SNAPSHOT. You may download a copy= from cvs and build yourself the jars or head to=0Ahttp://json-lib.sourcefo= rge.net/m2/repo/snapshot and download the latest snapshot.=0A=0APlease let = us know if it didn't work for you.=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 wh= o understand binary, and those who don't.=0ATo understand recursion, we= must first understand recursion.=0A=0A----- Mensaje original ----=0ADe: Yu= en Chi Lian <yue...@gm...>=0APara: jso...@li...urceforg= e.net=0AEnviado: s=E1bado, 29 de septiembre, 2007 0:21:42=0AAsunto: [json-l= ib-user] JSONObject.toBean() function fails on Bean with Bean[] setter/gett= er=0A=0AHi guys,=0A=0AI am choosing in between SOJO and JSON-lib for my new= project. JSON-lib seems to be well-maintained however I am having a diffic= ulty to convert from JSON to a bean with this structure:=0A=0ABeanA{=0A ge= t/set: BeanB[]=0A=0A get/set: String, whatever=0A}=0A=0ABeanB{=0A get/set= : String, whatever=0A}=0A=0ASample code and error:=0A=0AJSON json =3D JSONS= erializer.toJSON(REMOTE_ISSUE_STRING_1);=0AMap map =3D new HashMap();=0Amap= .put("customFieldValues", =0ARemoteCustomFieldValue.class);=0AJSONObject.to= Bean((JSONObject) json, RemoteIssue.class, map);=0A=0Anet.sf.json.JSONExcep= tion: Error while setting property=3DcustomfieldId typeclass java.lang.Stri= ng=0A at =0Anet.sf.json.JSONObject.toBean(JSONObject.java:453)=0A at = net.sf.json.JSONArray.toArray(JSONArray.java:294)=0A at net.sf.json.JSON= Object.toBean(JSONObject.java:386)=0A at org.mule.providers.jira.util.So= joUtilsTestCase.testJsonLibTypeFunctionalities=0A(SojoUtilsTestCase.java:48= )=0A at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)=0A = at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.j= ava:39)=0A at sun.reflect.DelegatingMethodAccessorImpl.invoke=0A(Delegat= ingMethodAccessorImpl.java:25)=0A at java.lang.reflect.Method.invoke(Met= hod.java:585)=0A at junit.framework.TestCase.runTest(TestCase.java:154)= =0A at junit.framework.TestCase.runBare(TestCase.java:127)=0A=0A at j= unit.framework.TestResult$1.protect(TestResult.java:106)=0A at junit.fra= mework.TestResult.runProtected(TestResult.java:124)=0A at junit.framewor= k.TestResult.run(TestResult.java:109)=0A at junit.framework.TestCase.run= =0A(TestCase.java:118)=0A at org.eclipse.jdt.internal.junit.runner.junit= 3.JUnit3TestReference.run(JUnit3TestReference.java:128)=0A at org.eclips= e.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)=0A=0A = at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(Remot= eTestRunner.java:460)=0A at org.eclipse.jdt.internal.junit.runner.Remote= TestRunner.runTests(RemoteTestRunner.java:673)=0A at org.eclipse.jdt.int= ernal.junit.runner.RemoteTestRunner.run=0A(RemoteTestRunner.java:386)=0A = at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestR= unner.java:196)=0ACaused by: java.lang.NoSuchMethodException: Unknown prope= rty 'customfieldId'=0A at =0Aorg.apache.commons.beanutils.PropertyUtilsB= ean.setSimpleProperty(PropertyUtilsBean.java:1741)=0A at org.apache.comm= ons.beanutils.PropertyUtils.setSimpleProperty(PropertyUtils.java:577)=0A = at net.sf.json.JSONObject.setProperty=0A(JSONObject.java:950)=0A at net= .sf.json.JSONObject.toBean(JSONObject.java:418)=0A ... 19 more=0A=0ABy d= oing some debugging and tracing, I found these lines in JSONObject:=0A=0Aif= ( List.class.isAssignableFrom( =0Apd.getPropertyType() ) ){=0A = Class targetClass =3D findTargetClass( key, classMap );=0A = targetClass =3D targetClass =3D=3D null ? findTargetClass( name= , classMap )=0A : targetClass;=0A=0A...=0A = }else{=0A Object array =3D JSONArray.toArray= ( (JSONArray) value, beanClass, classMap );=0A=0AIt is obvious that beanCla= ss as RemoteIssue is not going to work. I have tried putting RemoteFieldVal= ue[].class into the classMap too, but I knew that's not going to change any= thing.=0A=0A=0AIs there any workaround that you guys can suggest? Or should= I raise a feature/bug request on this?=0A=0A-- =0ACheers,=0AYuen-Chi Lian= =0A=0A"I do not seek; I find." - Pablo Picasso=0A=0A=0A=0A=0A=0A=0A __= ___________________________________________________________________________= _______=0A=A1S=E9 un mejor fot=F3grafo!=0APerfecciona tu t=E9cnica y encuen= tra las mejores fotos. =0Ahttp://mx.yahoo.com/promos/= mejorfotografo.html |
From: Yuen C. L. <yue...@gm...> - 2007-09-29 05:21:46
|
Hi guys, I am choosing in between SOJO and JSON-lib for my new project. JSON-lib seems to be well-maintained however I am having a difficulty to convert from JSON to a bean with this structure: BeanA{ get/set: BeanB[] get/set: String, whatever } BeanB{ get/set: String, whatever } Sample code and error: JSON json = JSONSerializer.toJSON(REMOTE_ISSUE_STRING_1); Map map = new HashMap(); map.put("customFieldValues", RemoteCustomFieldValue.class); JSONObject.toBean((JSONObject) json, RemoteIssue.class, map); net.sf.json.JSONException: Error while setting property=customfieldId typeclass java.lang.String at net.sf.json.JSONObject.toBean(JSONObject.java:453) at net.sf.json.JSONArray.toArray(JSONArray.java:294) at net.sf.json.JSONObject.toBean(JSONObject.java:386) at org.mule.providers.jira.util.SojoUtilsTestCase.testJsonLibTypeFunctionalities (SojoUtilsTestCase.java:48) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke( DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run( JUnit3TestReference.java:128) at org.eclipse.jdt.internal.junit.runner.TestExecution.run( TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run( RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196) Caused by: java.lang.NoSuchMethodException: Unknown property 'customfieldId' at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty( PropertyUtilsBean.java:1741) at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty( PropertyUtils.java:577) at net.sf.json.JSONObject.setProperty(JSONObject.java:950) at net.sf.json.JSONObject.toBean(JSONObject.java:418) ... 19 more By doing some debugging and tracing, I found these lines in JSONObject: if( List.class.isAssignableFrom( pd.getPropertyType() ) ){ Class targetClass = findTargetClass( key, classMap ); targetClass = targetClass == null ? findTargetClass( name, classMap ) : targetClass; ... }else{ Object array = JSONArray.toArray( (JSONArray) value, beanClass, classMap ); It is obvious that beanClass as RemoteIssue is not going to work. I have tried putting RemoteFieldValue[].class into the classMap too, but I knew that's not going to change anything. Is there any workaround that you guys can suggest? Or should I raise a feature/bug request on this? -- Cheers, Yuen-Chi Lian "I do not seek; I find." - Pablo Picasso |
From: <zha...@gm...> - 2007-09-28 08:11:41
|
json-lib-user mailing list submission |
From: Andres A. <aal...@ya...> - 2007-09-19 19:33:44
|
Hi Jerry,=0A=0AA quick test reveals that your problem is indeed a bug but h= as already=0Abeen fixed in the current development version, though an offic= ial release has not yet been made. The following code shows that when the '= nanos' property is being=0Aprocessed it will be skipped because the target = bean doesn't have a=0APropertyDescriptor for it.=0A=0A=0A=0A{"value":0,"dat= e":{"month":8,"day":3,"year":107,"nanos":0,"time":1190230433953,"seconds":5= 3,"timezoneOffset":300,"date":19,"hours":14,"minutes":33}}=0A=0A[07-09-19 1= 4:33:54] WARN [JSONObject:310] Property 'day' has no write method. SKIPPED= .=0A=0A[07-09-19 14:33:54] WARN [JSONObject:395] Tried to assign property = nanos:java.lang.Integer to bean of class java.util.Date=0A=0A[07-09-19 14:3= 3:54] WARN [JSONObject:310] Property 'timezoneOffset' has no write method.= SKIPPED.=0A=0A=0A=0AThere is no need to define exclusions or filters throu= gh JsonConfig (though you may do it to get rid of the warning).=0A=0AJson-l= ib 2.1-SNAPSHOT is available from http://json-lib.sourceforge.net/m2/repo/s= napshot/=0A=0AAn official release of 2.1 may take a little more time to all= ow for a couple of feature requests to be finished.=0A=0A=0A=0ACheers,=0A= =0AAndres =0A-------------------------------------------=0Ahttp://jroller.c= om/page/aalmiray=0Ahttp://www.linkedin.com/in/aalmiray=0A--=0AWhat goes up,= must come down. Ask any system administrator.=0AThere are 10 types of peop= le in the world: Those who understand binary, and those who don't.=0ATo= understand recursion, we must first understand recursion.=0A=0A----- Mensa= je original ----=0ADe: Gerardo Blanco <Bla...@ld...>=0APara: Andr= es Almiray <aal...@ya...>; jso...@li...=0AEnvi= ado: mi=E9rcoles, 19 de septiembre, 2007 11:36:42=0AAsunto: Re: [json-lib-u= ser] Casting classes=0A=0A=0A=0A =0A=0A=0A=0A=0A=0A=0A=0AI'm using version = 2. =0A=0A=0A =0A=0A=0AThe exception I got was =0A=0A=0A =0A=0A=0Anet.sf.jso= n.JSONException: Error while setting property=3Dnanos typeclass java.lang.I= ntegerHere's the code:JSONObject jsonObject =3D JSONObject.fromObject(myBea= n);System.out.println(myBean);MyBean b =3D (MyBean) JSONObject.toBean(jsonO= bject, MyBean.class);=0ASystem.out.println(b); Here's the bean def:import j= ava.util.Date;public class MyBean {...@Column(name=3D"PS_EFFECTIVE_DATE")= =0ADate psEffectiveDate;=0A...public Date getPsEffectiveDate() {=0A retur= n psEffectiveDate;=0A}=0A...public void setPsEffectiveDate(Date psEffective= Date) {=0A this.psEffectiveDate =3D psEffectiveDate;=0A }...}And this is t= he section of the JSON string that shows the object:,"psEffectiveDate":{"mo= nth":0,"day":1,"year":0,"nanos":0,"time":-2208963600000,"seconds":0,"timezo= neOffset":420,"date":1,"hours":0,"minutes":0},If I comment out the last two= lines in the code (where I create a new MyBean, etc), the whole process wo= rks fine. If I leave them, it fails when creating the bean b. Any comments?= -------------------------------------------------------=0AGerardo (Jerry) = R. Blanco =0ASoftware Engineer=0ALDS Platform Team=0A(801) 240-6978=0ABlanc= oG...@ld... =0A------------------------------------------------------= -=0A"I am endeavoring, ma'am, to construct a mnemonic memory circuit, using= stone knives and bearskins." -- Spock=0A>>> Andres Almiray <aalmiray@yahoo= .com> 9/19/2007 9:41 AM >>>=0A=0A=0A=0A=0A=0AHi Jerry,=0ASince version 0.9 = (I think) there is the option to specify a set of exclusions that will let = filter out some properties when using JSONObject.fromObject(), in your case= =0A=0A/* available in json-lib 1.x */=0AJSON json =3D JSONSerializer.toJSON= ( bean, new String[]{ "nanos"} );=0AJSONSerializer jsonSerializer =3D new J= SONSerializer();=0AjsonSerializer.setRootClass( Bean.class );=0ABean bean = =3D (Bean) jsonSerializer.toJava( json );=0A=0A/* the following is from 2.1= -SNAPSHOT */=0AJsonConfig jsonConfig =3D new JsonConfig();=0AjsonConfig.set= Excludes( new String[]{ "nanos"} );=0AJSON json =3D JSONSerializer.toJSON( = bean, jsonConfig );=0A...=0AjsonConfig.setRootClass( Bean.class );=0ABean b= ean =3D (Bean) JSONSerializer.toJava( json, jsonConfig );=0A =0AIn 2.1-SNAP= SHOT there is also the option to setup filters that will be enabled when se= rializing to JSON and transforming back to Java=0A=0AI'm quite surprised th= at 'nanos' gave caused a problem because the code should check if there is = a PropertyDescriptor that matches the target class and property, if so it w= ill also check if it has a proper writeMethod. Which version are you using?= =0A=0ARegards,=0AAndres=0A=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 thos= e who don't.=0ATo understand recursion, we must first understand recurs= ion.=0A=0A=0A=0A=0A=0A----- Mensaje original ----=0ADe: Gerardo Blanco <Bla= nc...@ld...>=0APara: jso...@li...=0AEnviado:= mi=E9rcoles, 19 de septiembre, 2007 10:30:45=0AAsunto: [json-lib-user] Cas= ting classes=0A=0A=0A=0AHi, =0A=0A=0A =0A=0A=0AI'm doing the following:=0A= =0A=0A =0A=0A=0A1) Run a Hibernate query to populate a bean=0A=0A=0A2) usin= g JSONObject.fromObject(bean)=0A=0A=0A3) using JSONObject.toBean()=0A=0A=0A= =0A=0A=0AThe problem is that the bean contains a java.util.Date. Hibernate= casts that to a java.sql.Timestamp, which extends java.util.Date, so Hiber= nate is complying with the contract.=0A=0A=0AWhen I create my JSONObject, t= he method fromObject grabs everything the Timestamp contains, including 'na= nos' (for nanoseconds). That property belongs to Timestamp.=0A=0A=0A =0A=0A= =0AWhen toBean is called, it doesn't know what to do with 'nanos' because i= t is introspecting java.util.Date.=0A=0A=0A =0A=0A=0AI know I can code arou= nd this issue by modifying my getters/setters, but my questions is: =0A=0A= =0Ashould this behaviour be caught (and provided for) by JSON-lib somehow?= =0A=0A=0A =0A=0A=0AWhat if we had JSONObject.fromObject(bean, Bean.class)? = That way JSONObject.fromObject would introspect the class, and only include= fields for the getters/setters for the actual class, instead of extended c= lasses that might be present.=0A=0A=0A =0A=0A=0AThanks.=0A=0A=0AJerry. =0A= =0A=0A =0A=0A=0A-------------------------------------------------------=0AG= erardo (Jerry) R. Blanco =0ASoftware Engineer=0ALDS Platform Team=0A(801) 2= 40-6978=0AB...@ld... =0A---------------------------------------= ----------------=0A"I am endeavoring, ma'am, to construct a mnemonic memory= circuit, using stone knives and bearskins." -- Spock=0ANOTICE: This email = message is for the sole use of the intended recipient(s) and may contain co= nfidential and privileged information. Any unauthorized review, use, disclo= sure or distribution is prohibited. If you are not the intended recipient, = please contact the sender by reply email and destroy all copies of the orig= inal message.=0A=0A=0A=0A=0A=0A=0A=0A=0A=0A=0A=A1S=E9 un mejor fot=F3grafo!= =0APerfecciona tu t=E9cnica y encuentra las mejores fotos en:=0Ahttp://mx.y= ahoo.com/promos/mejorambientalista.html =0A=0ANOTICE: This email message is= for the sole use of the intended recipient(s) and may contain confidential= and privileged information. Any unauthorized review, use, disclosure or di= stribution is prohibited. If you are not the intended recipient, please con= tact the sender by reply email and destroy all copies of the original messa= ge.=0A=0A=0A=0A=0A=0A=0A=0A __________________________________________= __________________________________________=0A=A1S=E9 un mejor asador!=0AApr= ende todo sobre asados. =0Ahttp://mx.yahoo.com/promos/= mejorasador.html |
From: Gerardo B. <Bla...@ld...> - 2007-09-19 16:37:02
|
SSdtIHVzaW5nIHZlcnNpb24gMi4gDQoNClRoZSBleGNlcHRpb24gSSBnb3Qgd2FzIA0KDQpuZXQu c2YuanNvbi5KU09ORXhjZXB0aW9uOiBFcnJvciB3aGlsZSBzZXR0aW5nIHByb3BlcnR5PW5hbm9z IHR5cGVjbGFzcyBqYXZhLmxhbmcuSW50ZWdl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NhIHkg ZW5jdWVudHJhIGxhcyBtZWpvcmVzIGZvdG9zIGVuOg0KaHR0cDovL214LnlhaG9vLmNvbS9wcm9t b3MvbWVqb3JhbWJpZW50YWxpc3RhLmh0bWwgCgotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tCk5PVElDRTogVGhpcyBl bWFpbCBtZXNzYWdlIGlzIGZvciB0aGUgc29sZSB1c2Ugb2YgdGhlIGludGVuZGVkIHJlY2lwaWVu dChzKSBhbmQgbWF5IGNvbnRhaW4gY29uZmlkZW50aWFsIGFuZCBwcml2aWxlZ2VkIGluZm9ybWF0 aW9uLiBBbnkgdW5hdXRob3JpemVkIHJldmlldywgdXNlLCBkaXNjbG9zdXJlIG9yIGRpc3RyaWJ1 dGlvbiBpcyBwcm9oaWJpdGVkLiBJZiB5b3UgYXJlIG5vdCB0aGUgaW50ZW5kZWQgcmVjaXBpZW50 LCBwbGVhc2UgY29udGFjdCB0aGUgc2VuZGVyIGJ5IHJlcGx5IGVtYWlsIGFuZCBkZXN0cm95IGFs bCBjb3BpZXMgb2YgdGhlIG9yaWdpbmFsIG1lc3NhZ2UuCg== |
From: Andres A. <aal...@ya...> - 2007-09-19 15:41:30
|
Hi Jerry,=0A=0ASince version 0.9 (I think) there is the option to specify a= set of=0Aexclusions that will let filter out some properties when using=0A= JSONObject.fromObject(), in your case=0A=0A=0A=0A/* available in json-lib 1= .x */=0A=0AJSON json =3D JSONSerializer.toJSON( bean, new String[]{ "nanos"= } );=0A=0AJSONSerializer jsonSerializer =3D new JSONSerializer();=0A=0Ajson= Serializer.setRootClass( Bean.class );=0A=0ABean bean =3D (Bean) jsonSerial= izer.toJava( json );=0A=0A=0A=0A/* the following is from 2.1-SNAPSHOT */=0A= =0AJsonConfig jsonConfig =3D new JsonConfig();=0A=0AjsonConfig.setExcludes(= new String[]{ "nanos"} );=0A=0AJSON json =3D JSONSerializer.toJSON( bean, = jsonConfig );=0A=0A...=0A=0AjsonConfig.setRootClass( Bean.class );=0A=0ABea= n bean =3D (Bean) JSONSerializer.toJava( json, jsonConfig );=0A =0A=0AIn 2.= 1-SNAPSHOT there is also the option to setup filters that will be=0Aenabled= when serializing to JSON and transforming back to Java=0A=0A=0A=0AI'm quit= e surprised that 'nanos' gave caused a problem because the code=0Ashould ch= eck if there is a PropertyDescriptor that matches the target=0Aclass and pr= operty, if so it will also check if it has a proper=0AwriteMethod. Which ve= rsion are you using?=0A=0A=0A=0ARegards,=0A=0AAndres =0A-------------------= ------------------------=0Ahttp://jroller.com/page/aalmiray=0Ahttp://www.li= nkedin.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 under= stand binary, and those who don't.=0ATo understand recursion, we must f= irst understand recursion.=0A=0A----- Mensaje original ----=0ADe: Gerardo B= lanco <Bla...@ld...>=0APara: jso...@li...= =0AEnviado: mi=E9rcoles, 19 de septiembre, 2007 10:30:45=0AAsunto: [json-li= b-user] Casting classes=0A=0A=0A=0A =0A=0A=0A=0AHi, =0A=0A=0A =0A=0A=0AI'm = doing the following:=0A=0A=0A =0A=0A=0A1) Run a Hibernate query to populate= a bean=0A=0A=0A2) using JSONObject.fromObject(bean)=0A=0A=0A3) using JSONO= bject.toBean()=0A=0A=0A =0A=0A=0AThe problem is that the bean contains a ja= va.util.Date. Hibernate casts that to a java.sql.Timestamp, which extends j= ava.util.Date, so Hibernate is complying with the contract.=0A=0A=0AWhen I = create my JSONObject, the method fromObject grabs everything the Timestamp = contains, including 'nanos' (for nanoseconds). That property belongs to Tim= estamp.=0A=0A=0A =0A=0A=0AWhen toBean is called, it doesn't know what to do= with 'nanos' because it is introspecting java.util.Date.=0A=0A=0A =0A=0A= =0AI know I can code around this issue by modifying my getters/setters, but= my questions is: =0A=0A=0Ashould this behaviour be caught (and provided fo= r) by JSON-lib somehow?=0A=0A=0A =0A=0A=0AWhat if we had JSONObject.fromObj= ect(bean, Bean.class)? That way JSONObject.fromObject would introspect the = class, and only include fields for the getters/setters for the actual class= , instead of extended classes that might be present.=0A=0A=0A =0A=0A=0AThan= ks.=0A=0A=0AJerry. =0A=0A=0A =0A=0A=0A-------------------------------------= ------------------=0AGerardo (Jerry) R. Blanco =0ASoftware Engineer=0ALDS P= latform Team=0A(801) 240-6978=0AB...@ld... =0A-----------------= --------------------------------------=0A"I am endeavoring, ma'am, to const= ruct a mnemonic memory circuit, using stone knives and bearskins." -- Spock= =0A=0ANOTICE: This email message is for the sole use of the intended recipi= ent(s) and may contain confidential and privileged information. Any unautho= rized review, use, disclosure or distribution is prohibited. If you are not= the intended recipient, please contact the sender by reply email and destr= oy all copies of the original message.=0A=0A=0A=0A=0A=0A=0A=0A _______= ___________________________________________________________________________= __=0A=A1S=E9 un mejor ambientalista!=0AEncuentra consejos para cuidar el lu= gar donde vivimos. =0Ahttp://mx.yahoo.com/promos/mejo= rambientalista.html |
From: Gerardo B. <Bla...@ld...> - 2007-09-19 15:31:09
|
SGksIA0KDQpJJ20gZG9pbmcgdGhlIGZvbGxvd2luZzoNCg0KMSkgUnVuIGEgSGliZXJuYXRlIHF1 ZXJ5IHRvIHBvcHVsYXRlIGEgYmVhbg0KMikgdXNpbmcgSlNPTk9iamVjdC5mcm9tT2JqZWN0KGJl YW4pDQozKSB1c2luZyBKU09OT2JqZWN0LnRvQmVhbigpDQoNClRoZSBwcm9ibGVtIGlzIHRoYXQg dGhlIGJlYW4gY29udGFpbnMgYSBqYXZhLnV0aWwuRGF0ZS4gSGliZXJuYXRlIGNhc3RzIHRoYXQg dG8gYSBqYXZhLnNxbC5UaW1lc3RhbXAsIHdoaWNoIGV4dGVuZHMgamF2YS51dGlsLkRhdGUsIHNv IEhpYmVybmF0ZSBpcyBjb21wbHlpbmcgd2l0aCB0aGUgY29udHJhY3QuDQpXaGVuIEkgY3JlYXRl IG15IEpTT05PYmplY3QsIHRoZSBtZXRob2QgZnJvbU9iamV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c4DQpCbGFuY29HUkBsZHNjaHVyY2gub3JnIA0K LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQ0K IkkgYW0gZW5kZWF2b3JpbmcsIG1hJ2FtLCB0byBjb25zdHJ1Y3QgYSBtbmVtb25pYyBtZW1vcnkg Y2lyY3VpdCwgdXNpbmcgc3RvbmUga25pdmVzIGFuZCBiZWFyc2tpbnMuIiAtLSBTcG9jawoKLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLQpOT1RJQ0U6IFRoaXMgZW1haWwgbWVzc2FnZSBpcyBmb3IgdGhlIHNvbGUgdXNl IG9mIHRoZSBpbnRlbmRlZCByZWNpcGllbnQocykgYW5kIG1heSBjb250YWluIGNvbmZpZGVudGlh bCBhbmQgcHJpdmlsZWdlZCBpbmZvcm1hdGlvbi4gQW55IHVuYXV0aG9yaXplZCByZXZpZXcsIHVz ZSwgZGlzY2xvc3VyZSBvciBkaXN0cmlidXRpb24gaXMgcHJvaGliaXRlZC4gSWYgeW91IGFyZSBu b3QgdGhlIGludGVuZGVkIHJlY2lwaWVudCwgcGxlYXNlIGNvbnRhY3QgdGhlIHNlbmRlciBieSBy ZXBseSBlbWFpbCBhbmQgZGVzdHJveSBhbGwgY29waWVzIG9mIHRoZSBvcmlnaW5hbCBtZXNzYWdl Lgo= |
From: Matt S. <ms...@ac...> - 2007-08-30 01:16:12
|
That sounds great to me. Being able to pass JsonConfig objects in will let me manage my own (by object type, say), so I think it's better than the ThreadLocal. I'll look forward to the fix! Thanks, Matt Andres Almiray wrote: > Hi Matt, > Currently there is no workaround for it. I'm thinking that > the best choice is an hybrid approach: > 1) JsonConfig will not be a singleton > 2) JSONSerializer and *.fromObject will accept a JsonConfig parameter > > At first JsonConfig was a ThreadLocal bound singleton but then > I changed my mind, that's why it is a singleton now. This > question has already appeared at the forums and I think > it is important to have it solved quickly. I'll have the fix by > the next week and available in the snapshot repo. > > 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: Matt Small <ms...@ac...> > Para: jso...@li.... > Enviado: miércoles, 29 de agosto, 2007 18:55:34 > Asunto: [json-lib-user] JsonConfig & Threads > > I'm taking a look at the new json-lib 2.0, it looks great! > > It seems as though a lot of the general configuration about > serialization has been taken out in the JsonConfig object. This doesn't > appear to be Thread-safe; if you have two threads serializing different > objects (presumably with different configurations), one will clobber the > other's JsonConfig. > > Is this correct? Any workarounds, or is there a different/better way to > do the serialization configuration (particularly excludes for me, right > now) in a Thread-safe manner? > > Thanks, > Matt > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > json-lib-user mailing list > jso...@li... > https://lists.sourceforge.net/lists/listinfo/json-lib-user > > > ------------------------------------------------------------------------ > > ¡Sé un mejor besador! > Comparte todo lo que sabes sobre besos en: > http://mx.yahoo.com/promos/mejorbesador.html |
From: Andres A. <aal...@ya...> - 2007-08-30 00:04:32
|
Hi Matt,=0ACurrently there is no workaround for it. I'm thinking that=0Athe= best choice is an hybrid approach:=0A1) JsonConfig will not be a singleton= =0A2) JSONSerializer and *.fromObject will accept a JsonConfig parameter=0A= =0AAt first JsonConfig was a ThreadLocal bound singleton but then=0AI chang= ed my mind, that's why it is a singleton now. This=0Aquestion has already a= ppeared at the forums and I think=0Ait is important to have it solved quick= ly. I'll have the fix by=0Athe next week and available in the snapshot repo= .=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 thos= e who don't.=0ATo understand recursion, we must first understand recurs= ion.=0A=0A----- Mensaje original ----=0ADe: Matt Small <msmall@activegrid.c= om>=0APara: jso...@li....=0AEnviado: mi=E9rcoles, 29= de agosto, 2007 18:55:34=0AAsunto: [json-lib-user] JsonConfig & Threads=0A= =0AI'm taking a look at the new json-lib 2.0, it looks great!=0A=0AIt seems= as though a lot of the general configuration about =0Aserialization has be= en taken out in the JsonConfig object. This doesn't =0Aappear to be Thread= -safe; if you have two threads serializing different =0Aobjects (presumably= with different configurations), one will clobber the =0Aother's JsonConfig= .=0A=0AIs this correct? Any workarounds, or is there a different/better wa= y to =0Ado the serialization configuration (particularly excludes for me, r= ight =0Anow) in a Thread-safe manner?=0A=0AThanks,=0AMatt=0A=0A------------= -------------------------------------------------------------=0AThis SF.net= email is sponsored by: Splunk Inc.=0AStill grepping through log files to f= ind problems? Stop.=0ANow Search log events and configuration files using = AJAX and a browser.=0ADownload your FREE copy of Splunk now >> http://get.= splunk.com/=0A_______________________________________________=0Ajson-lib-us= er mailing list=0Aj...@li...=0Ahttps://lists.sourc= eforge.net/lists/listinfo/json-lib-user=0A=0A=0A=0A=0A=0A=0A=0A ______= ___________________________________________________________________________= ___=0A=A1S=E9 un mejor asador!=0AAprende todo sobre asados. = =0Ahttp://mx.yahoo.com/promos/mejorasador.html |
From: Matt S. <ms...@ac...> - 2007-08-29 23:55:45
|
I'm taking a look at the new json-lib 2.0, it looks great! It seems as though a lot of the general configuration about serialization has been taken out in the JsonConfig object. This doesn't appear to be Thread-safe; if you have two threads serializing different objects (presumably with different configurations), one will clobber the other's JsonConfig. Is this correct? Any workarounds, or is there a different/better way to do the serialization configuration (particularly excludes for me, right now) in a Thread-safe manner? Thanks, Matt |
From: <liu...@gm...> - 2007-08-21 07:36:29
|
json-lib version: 2.0 jdk15 public static void main(String[] args) { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> m = new HashMap<String, Object>(); m.put("name", "json-lib"); list.add(m); JSONObject json = JSONObject.fromObject(list); System.out.println(json.toString()); } Exception in thread "main" net.sf.json.JSONException: 'object' is an array. Use JSONArray instead at net.sf.json.JSONObject.fromObject(JSONObject.java:255) at Main2.main(Main2.java:18) |