json-lib-user Mailing List for Json-lib (Page 3)
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: Philippe A. <fut...@gm...> - 2009-10-30 17:36:43
|
Hello! I would like to propose adding the isNullObject method into the JSON interface. The current way to determine if an object is null is by comparing the result of toString with the "null" string. This is the only method common to NULLObject and JSONObject allowing to do that. It works but it is not as efficient as isNullObject since time must be spent building a string representation of the object if it is not null. Besides adding the declaration in the JSON interface, it would be only a matter of implementing a function returning true in JSONNull. Obviously it would break compatibility for those who implemented the JSON interface for other purposes. Let me know what you think. |
From: Petr K. <kob...@gm...> - 2009-09-24 18:47:57
|
Hi list, how are handled dates in json-lib? I have this code: JsonConfig conf = new JsonConfig(); conf.addIgnoreFieldAnnotation("permissions"); Session session = JflyRequestCycle.get().getDBSession(); List<User> users = (List<User>)session.createQuery( "select j_user from User as j_user order by j_user.nickname" ).list(); return JSONArray.fromObject(users, conf); and this throws this exception: ... Caused by: net.sf.json.JSONException: java.lang.reflect.InvocationTargetException at net.sf.json.JSONObject._fromBean(JSONObject.java:987) at net.sf.json.JSONObject.fromObject(JSONObject.java:168) at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) at net.sf.json.JSONObject._processValue(JSONObject.java:2808) at net.sf.json.JSONObject.processValue(JSONObject.java:2874) at net.sf.json.JSONObject.setInternal(JSONObject.java:2889) at net.sf.json.JSONObject.setValue(JSONObject.java:1577) at net.sf.json.JSONObject._fromBean(JSONObject.java:934) at net.sf.json.JSONObject.fromObject(JSONObject.java:168) at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) at net.sf.json.JSONArray._processValue(JSONArray.java:2514) at net.sf.json.JSONArray.processValue(JSONArray.java:2539) at net.sf.json.JSONArray.addValue(JSONArray.java:2526) at net.sf.json.JSONArray._fromCollection(JSONArray.java:1057) at net.sf.json.JSONArray.fromObject(JSONArray.java:123) at com.jfly.core.services.UserService.list(UserService.java:30) ... 38 more Caused by: java.lang.reflect.InvocationTargetException 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:597) at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2155) at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1323) at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:762) at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:837) at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426) at net.sf.json.JSONObject._fromBean(JSONObject.java:918) ... 53 more Caused by: java.lang.IllegalArgumentException at java.sql.Date.getHours(Date.java:143) ... 63 more I tracked it down and it's in java.sql.Date.getHours: public int getHours() { throw new java.lang.IllegalArgumentException(); } Is this my problem, json-lib problem or it's somewhere else? Thanks for reply - Petr |
From: Andres A. <aal...@ya...> - 2009-09-21 16:33:33
|
Hi Rodolfo, Looks like a bug to me. Please file a bug ticket, thank you! Cheers, Andres ------------------------------------------- http://jroller.com/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. ________________________________ From: Rodolfo Bunney <ro...@id...> To: jso...@li... Sent: Monday, September 21, 2009 2:17:56 AM Subject: [json-lib-user] Problem collecting elements of identical name in a array Hi! I'm trying to write JSON from an existing XML document and got a problem with collecting all the elements with identical names. If my identical named elements are the only ones in the same depth in the XML document, the parser has no problem converting the document. But if I have several siblings where a couple of them are identical, the result JSON is not transformed correctly. I'm doing this from a Groovy script.: import net.sf.json.xml.XMLSerializer import net.sf.json.JSON def xml = """<body> <menulist> <titles><foo>foo1</foo><foo>foo2</foo></titles> <item> <value><name>item1</name><action>doAction</action></value> </item> <item> <value><name>item2</name><action>doAction</action></value> </item> </menulist> </body>""" XMLSerializer serializer = new XMLSerializer() JSON json = serializer.read(xml) return json.toString() The JSON result: [ { "titles": [ "foo1", "foo2" ], "item": [ { "name": "item1", "action": "doAction" }, [ { "name": "item2", "action": "doAction" } ] ] } ] If I remove the <titles> node the XML document is correctly parsed. Does anyone else have the same problem? Or maybe have a nice workaround? -- Rodolfo Bunney <ro...@id...> Systemutvikler @ http://www.idium.no Sommerrogata 13-15, N-0255 Oslo, Norway 22 00 84 00 |
From: Christoph S. <sun...@ho...> - 2009-09-21 15:33:49
|
Hi! Is there an option to drop the JSON root-element when unmarshalling JSON to a Java bean? Incomming JSON: { "simplebean": { "key":"value", "key2":"value" } } Target class: public class DifferentNameBean { String key; String key2; ... } _________________________________________________________________ http://redirect.gimas.net/?n=M0909xWindows7_2 Schnell, zuverlässig, einfach: jetzt Windows 7 kennenlernen! |
From: Rodolfo B. <ro...@id...> - 2009-09-21 09:18:15
|
Hi! I'm trying to write JSON from an existing XML document and got a problem with collecting all the elements with identical names. If my identical named elements are the only ones in the same depth in the XML document, the parser has no problem converting the document. But if I have several siblings where a couple of them are identical, the result JSON is not transformed correctly. I'm doing this from a Groovy script.: import net.sf.json.xml.XMLSerializer import net.sf.json.JSON def xml = """<body> <menulist> <titles><foo>foo1</foo><foo>foo2</foo></titles> <item> <value><name>item1</name><action>doAction</action></value> </item> <item> <value><name>item2</name><action>doAction</action></value> </item> </menulist> </body>""" XMLSerializer serializer = new XMLSerializer() JSON json = serializer.read(xml) return json.toString() The JSON result: [ { "titles": [ "foo1", "foo2" ], "item": [ { "name": "item1", "action": "doAction" }, [ { "name": "item2", "action": "doAction" } ] ] } ] If I remove the <titles> node the XML document is correctly parsed. Does anyone else have the same problem? Or maybe have a nice workaround? -- Rodolfo Bunney <ro...@id...> Systemutvikler @ http://www.idium.no Sommerrogata 13-15, N-0255 Oslo, Norway 22 00 84 00 |
From: Andres A. <aal...@ya...> - 2009-07-11 22:59:46
|
Dear Users, I'm pleased to announce that Json-lib version 2.3 has been released. Download | Documentation | Faq | Changes JSON-lib is a java library for transforming beans, maps and XML to JSON and back again to beans and DynaBeans. It is based on the work by Douglas Crockford in http://www.json.org/java. Changelog: * 2795511 Maps with non-String keys throw ClassCastException * 2799533 Incorrect event firing on cycles * 2807279 JSONObject Map.size() implementation is incorrect. Thanks to Earl Nolan (provided testcase) * 2818666 Annotation filter * 2817570 net.sf.json.util.JSONUtils.isFunction() locks. Thanks to Ian Wolfcat Atha (provided patch) * 2779977 Inconsistent license between the source file and project * 2513691 Support for reading both properties and public fields * 2776558 undefined not an acceptable parser token * 2431487 Allow JSONArray/JSONObject to be Serializable * 2682840 JsonValueProcessor not processing primitive arrays (breaking change!) * 2665846 Memory Leak in Cycle Detection * 2565295 Problems detecting an unreadable property * 2792844 Log level: warn vs. info for skipped properties * 2790052 Improve exception message on NewBeanInstanceStrategy. Thanks to Henrik Johansson (provided patch) |
From: Pedro A. <pe...@ne...> - 2009-06-30 18:27:32
|
Hello. I have a webapp that has textareas where the users can input anything, including javascript code. The problem is that I can't make jslib treat stuff like "function(){}" as a string. Is there any specific rule to encapsulate it? Whatever I do it either returns "\"function(){}\"" or a JSONFunction, I can never get a string with the chart "function()" Thanks -- Pedro Alves pmgalves-at-gmail.com |
From: zapping z. <zap...@ya...> - 2009-06-03 05:40:23
|
Hi, Thank you. Got it to work with JSONObject jsonResponse = JSONObject.fromObject(strResponse); and also there was no need to do the replacement function etc this way was able to use the same response string as in javascript. Cheers and thx for the lib ________________________________ From: zapping zapping <zap...@ya...> To: jso...@li... Sent: Tuesday, June 2, 2009 9:34:44 PM Subject: [json-lib-user] Parsing problem Hi, I have a json string that is returned from a service like {success:"true",code:"200",dataType:"object",objClass:"Message",data:{text:"The room is free. You can start a meeting"}} When i try to parse it JSONObject jsonResponse = (JSONObject)JSONSerializer.toJSON(strResponse); I get an Invalid exception. But the same response string i am able to parse with javascript but not in Java. Tried replacing the quotes with strResponse = strResponse.replaceAll("\"", "\\\\\""); But still throws invalid exception. But when i try it this way with a constant it parses String strResponse = "{success:\"false\",code:\"300\",dataType:\"object\",objClass:\"Message\",data:{text:\"Unparseable date: 'June 03 2009 11:15:00 AM EDT'\"}}"; JSONObject jsonResponse = (JSONObject)JSONSerializer.toJSON(strResponse); But not directly from the service. Can you help me out. Thx, Zaps |
From: zapping z. <zap...@ya...> - 2009-06-02 16:04:46
|
Hi, I have a json string that is returned from a service like {success:"true",code:"200",dataType:"object",objClass:"Message",data:{text:"The room is free. You can start a meeting"}} When i try to parse it JSONObject jsonResponse = (JSONObject)JSONSerializer.toJSON(strResponse); I get an Invalid exception. But the same response string i am able to parse with javascript but not in Java. Tried replacing the quotes with strResponse = strResponse.replaceAll("\"", "\\\\\""); But still throws invalid exception. But when i try it this way with a constant it parses String strResponse = "{success:\"false\",code:\"300\",dataType:\"object\",objClass:\"Message\",data:{text:\"Unparseable date: 'June 03 2009 11:15:00 AM EDT'\"}}"; JSONObject jsonResponse = (JSONObject)JSONSerializer.toJSON(strResponse); But not directly from the service. Can you help me out. Thx, Zaps |
From: Tim P. <tim...@ou...> - 2009-05-19 16:28:35
|
Hi Andres, On Tuesday 19 May 2009 16:28:26 Andres Almiray wrote: > Hi Tim, > > Thank you for checking out Json-lib, we hope it proves to be helpful to > you. Now answers to your questions: > > > "JSONObject uses a HashMap for its properties > representation because the order of its properties is not important." > - this is no longer true, as a matter of fact JSONObject uses a > LinkedHashMap to preserver insertion order, the FAQ must be updated. Have > in mind that the JSON semantics still declare a JSONObject to be a Bag, per > the spec. Good, I thought so, as I had looked at the code and saw you were now preserving insertion order. > " What is the relationship to json.org?" > - Json-lib was born from the code found at json.org and evolved from there. Yes, but Mr Crockford is not actually a developer on this project? I think it is important to spell out clearly whether this is a derived project or one that is actively developed by the originators of JSON. [snip - ant usage] > "Oh, I forgot, the main problem, which prompted me to join the list, > is that the optional setting on the xom jar caused me to have a runtime > error reported by a user. " > - an optional dependency means you don't need to download it in order to > use the library, however you must download it in order to compile one part > of the library (xml support). yes, I know what it means, now, after it caused me pain. I see the use of optional for the ORO library, but not for XOM you have askd be to read your POM and determine whether I need to manuall include the XOM jar. This is not the Maven way. I am happy to download enormous numbers of jars that I may or may not need, I am not happy having to make decisions about it. I think removing optional on the XOM jar would be good. > Cheers, > Andres cheers and thanks for your library Tim |
From: Andres A. <aal...@ya...> - 2009-05-19 15:28:31
|
Hi Tim, Thank you for checking out Json-lib, we hope it proves to be helpful to you. Now answers to your questions: "JSONObject uses a HashMap for its properties representation because the order of its properties is not important." - this is no longer true, as a matter of fact JSONObject uses a LinkedHashMap to preserver insertion order, the FAQ must be updated. Have in mind that the JSON semantics still declare a JSONObject to be a Bag, per the spec. " What is the relationship to json.org?" - Json-lib was born from the code found at json.org and evolved from there. "It looks like you have stopped using Maven to actually build the artefacts, I am new to the list and would like to know why." - this is due to the current jdk3/jdk5 setup, given that maven is unable to handle several source paths that may contain "duplicate" class definitions. We tried using maven's ant plugin but it didn't quite work, nor maven's profile option. These days the Ant build does all the work, but still uses the pom file for dependency management "Oh, I forgot, the main problem, which prompted me to join the list, is that the optional setting on the xom jar caused me to have a runtime error reported by a user. " - an optional dependency means you don't need to download it in order to use the library, however you must download it in order to compile one part of the library (xml support). Cheers, Andres ------------------------------------------- http://jroller.com/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. ________________________________ From: Tim Pizey <tim...@ou...> To: jso...@li... Sent: Tuesday, May 19, 2009 2:58:08 AM Subject: [json-lib-user] First impressions Hi, I am just starting with json-lib, and thought you might like to see where I bump into the furniture: I came to json-lib as a replacement for org.json in the hope of getting junit testing facilities, which I have got, thank you. I would be interested in more about FAQ 1, as I cannot see any situation in which a Bag is the right choice: the population order is of interest and should be preserved. To do otherwise is to throw information away. The bald statement "JSONObject uses a HashMap for its properties representation because the order of its properties is not important." is a bit strong for me. Whilst I am sure that it is correct I would like to know what would happen if this assumption were not so central. I like to round trip in unit tests, the throwing away of information, ie the deliberate removal of ordering means that I am unable to do this with ease, am not able to use string comparision for equality and have had to put in a lot of work. Would it not have been possible to preserve the ordering? Would the performance hot have been so bad? FAQ What is the relationship to json.org? It looks like you have stopped using Maven to actually build the artefacts, I am new to the list and would like to know why. When I checkout and type mvn install I get test failure (Kubuntu/sun java6/AMD64) cheers Tim [INFO] Surefire report directory: /dist/json-lib/target/surefire-reports org.apache.maven.surefire.booter.SurefireExecutionException: Unable to instantiate POJO 'class net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor'; nested exception is java.lang.InstantiationException: net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor; nested exception is org.apache.maven.surefire.testset.TestSetFailedException: Unable to instantiate POJO 'class net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor'; nested exception is java.lang.InstantiationException: net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor org.apache.maven.surefire.testset.TestSetFailedException: Unable to instantiate POJO 'class net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor'; nested exception is java.lang.InstantiationException: net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor java.lang.InstantiationException: net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor at java.lang.Class.newInstance0(Class.java:340) at java.lang.Class.newInstance(Class.java:308) ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ json-lib-user mailing list jso...@li... https://lists.sourceforge.net/lists/listinfo/json-lib-user |
From: Tim P. <tim...@ou...> - 2009-05-19 10:14:19
|
On Tuesday 19 May 2009 10:58:08 Tim Pizey wrote: > Hi, > > I am just starting with json-lib, and thought you might like to see > where I bump into the furniture: Oh, I forgot, the main problem, which prompted me to join the list, is that the optional setting on the xom jar caused me to have a runtime error reported by a user. I use Maven so as to have my dependencies managed. I have never before encountered the optional flag. I am sure you have good reasons for using it, but thought you might like to know that it bit me. cheers Tim |
From: Tim P. <tim...@ou...> - 2009-05-19 09:58:26
|
Hi, I am just starting with json-lib, and thought you might like to see where I bump into the furniture: I came to json-lib as a replacement for org.json in the hope of getting junit testing facilities, which I have got, thank you. I would be interested in more about FAQ 1, as I cannot see any situation in which a Bag is the right choice: the population order is of interest and should be preserved. To do otherwise is to throw information away. The bald statement "JSONObject uses a HashMap for its properties representation because the order of its properties is not important." is a bit strong for me. Whilst I am sure that it is correct I would like to know what would happen if this assumption were not so central. I like to round trip in unit tests, the throwing away of information, ie the deliberate removal of ordering means that I am unable to do this with ease, am not able to use string comparision for equality and have had to put in a lot of work. Would it not have been possible to preserve the ordering? Would the performance hot have been so bad? FAQ What is the relationship to json.org? It looks like you have stopped using Maven to actually build the artefacts, I am new to the list and would like to know why. When I checkout and type mvn install I get test failure (Kubuntu/sun java6/AMD64) cheers Tim [INFO] Surefire report directory: /dist/json-lib/target/surefire-reports org.apache.maven.surefire.booter.SurefireExecutionException: Unable to instantiate POJO 'class net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor'; nested exception is java.lang.InstantiationException: net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor; nested exception is org.apache.maven.surefire.testset.TestSetFailedException: Unable to instantiate POJO 'class net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor'; nested exception is java.lang.InstantiationException: net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor org.apache.maven.surefire.testset.TestSetFailedException: Unable to instantiate POJO 'class net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor'; nested exception is java.lang.InstantiationException: net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor java.lang.InstantiationException: net.sf.json.TestJSONObject$PrefixerPropertyNameProcessor at java.lang.Class.newInstance0(Class.java:340) at java.lang.Class.newInstance(Class.java:308) |
From: Andres A. <aal...@ya...> - 2009-05-11 15:24:28
|
Hi Marek, Looks like your bean class must be declared public, otherwise the bean introspection will fail. Cheers, Andres ------------------------------------------- http://jroller.com/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. ________________________________ From: Marek <xxx...@gm...> To: jso...@li... Sent: Sunday, May 10, 2009 5:41:46 AM Subject: [json-lib-user] Fwd: Property 'id' has no getter method in class... Hallo I have very simple example, but it doesn't go.There is print exception and classes: http://stargate.cnl.tuke.sk/%7Emaly/error |
From: Marek <xxx...@gm...> - 2009-05-10 12:41:51
|
Hallo I have very simple example, but it doesn't go.There is print exception and classes: http://stargate.cnl.tuke.sk/~maly/error<http://stargate.cnl.tuke.sk/%7Emaly/error> |
From: Marek <xxx...@gm...> - 2009-05-10 12:34:47
|
Hallo I have very simple example, but it doesn't go.There is print exception and classes: http://stargate.cnl.tuke.sk/~maly/error |
From: Leonard G. <Leo...@ma...> - 2009-05-01 23:35:48
|
Hi Andres and thanks for reply. The example demonstrates how to use defaultValueProcessor going java->Json; I need to do the reverse I have a JSON string that gets converted to JSONObject that get converted to Java. I have a call: MyBean obj = (MyBean) JSONObject.toBean(jsResponse, MyBean.class); When I tried to use JSONConfig with with defaultValueProcessor, it did not help much since all the types are the strings or list of strings. I noticed that that toBean() can also take JSonConfig - maybe there is something that can be passed there? Thanks ________________________________ From: Andres Almiray [mailto:aal...@ya...] Sent: Friday, May 01, 2009 12:06 PM To: Leonard Gestrin; jso...@li... Subject: Re: [json-lib-user] Is it possible to force JSONObject.toBean() throw exceptions on cast issues for primitives as oppose to using default values? Hi Leonard, Yes, you can register a DefaultValueProcessor to do just that. http://json-lib.sourceforge.net/advanced.html http://json-lib.sourceforge.net/xref-test/net/sf/json/TestJSONObject.html#812 http://json-lib.sourceforge.net/xref-test/net/sf/json/TestJSONObject.html#833 Cheers, Andres ------------------------------------------- http://jroller.com/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. ________________________________ From: Leonard Gestrin <lge...@gm...> To: jso...@li... Sent: Thursday, April 30, 2009 8:15:13 PM Subject: [json-lib-user] Is it possible to force JSONObject.toBean() throw exceptions on cast issues for primitives as oppose to using default values? Hello, ( I apologize if this is duplicate message) I noticed that if I have a bean that has primitive member with setters and getters and I try to instantiate it from JSON string that has invalid int for that member, EZ Morph is using default value 0 instead of throwing exceptions. I looked at the code of EZMorpth and I could not find an easy way to change that default behavior. I would like to be able to differentiate between invalid value and default value. Is there some easy trick I can use to do so? Thanks Leonard |
From: Andres A. <aal...@ya...> - 2009-05-01 19:05:56
|
Hi Leonard, Yes, you can register a DefaultValueProcessor to do just that. http://json-lib.sourceforge.net/advanced.html http://json-lib.sourceforge.net/xref-test/net/sf/json/TestJSONObject.html#812 http://json-lib.sourceforge.net/xref-test/net/sf/json/TestJSONObject.html#833 Cheers, Andres ------------------------------------------- http://jroller.com/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. ________________________________ From: Leonard Gestrin <lge...@gm...> To: jso...@li... Sent: Thursday, April 30, 2009 8:15:13 PM Subject: [json-lib-user] Is it possible to force JSONObject.toBean() throw exceptions on cast issues for primitives as oppose to using default values? Hello, ( I apologize if this is duplicate message) I noticed that if I have a bean that has primitive member with setters and getters and I try to instantiate it from JSON string that has invalid int for that member, EZ Morph is using default value 0 instead of throwing exceptions. I looked at the code of EZMorpth and I could not find an easy way to change that default behavior. I would like to be able to differentiate between invalid value and default value. Is there some easy trick I can use to do so? Thanks Leonard |
From: Leonard G. <lge...@gm...> - 2009-05-01 03:15:28
|
Hello, ( I apologize if this is duplicate message) I noticed that if I have a bean that has primitive member with setters and getters and I try to instantiate it from JSON string that has invalid int for that member, EZ Morph is using default value 0 instead of throwing exceptions. I looked at the code of EZMorpth and I could not find an easy way to change that default behavior. I would like to be able to differentiate between invalid value and default value. Is there some easy trick I can use to do so? Thanks Leonard |
From: Leonard G. <Leo...@ma...> - 2009-04-30 20:46:56
|
Hello, ( I apologize if this is duplicate message) I noticed that if I have a bean that has primitive member with setters and getters and I try to instantiate it from JSON string that has invalid int for that member, EZ Morph is using default value 0 instead of throwing exceptions. I looked at the code of EZMorpth and I could not find an easy way to change that default behavior. I would like to be able to differentiate between invalid value and default value. Is there some easy trick I can use to do so? Thanks Leonard |
From: Leonard G. <Leo...@ma...> - 2009-04-30 18:15:08
|
Hello, ( I apologize if this is duplicate message) I noticed that if I have a bean that has primitive member with setters and getters and I try to instantiate it from JSON string that has invalid int for that member, EZ Morph is using default value 0 instead of throwing exceptions. I looked at the code of EZMorpth and I could not find an easy way to change that default behavior. I would like to be able to differentiate between invalid value and default value. Is there some easy trick I can use to do so? Thanks Leonard |
From: Leonard G. <Leo...@ma...> - 2009-04-30 18:08:23
|
Hello, I noticed that if I have a bean that has primitive member with setters and getters and I try to instantiate it from JSON string that has invalid int for that member, EZ Morph is using default value 0 instead of throwing exceptions. I looked at the code of EZMorpth and I could not find an easy way to change that default behavior. I would like to be able to differentiate between invalid value and default value. Is there some easy trick I can use to do so? Thanks Leonard |
From: Jonathan <jso...@ki...> - 2009-04-14 20:24:18
|
Currently, json-lib will log a message at warn level if during the process of converting an object to json if finds a property descriptor without an attendant write method. See lines 362 and 698 of JSONObject: log.warn( "Property '" + key + "' of "+ root.getClass()+" has no write method. SKIPPED." ); There are several valid, expected reasons why this condition might occur. For instance, it turns out that the javaassist classes created by Hibernate often run into this situation. Would you consider changing the log level to info for these statements? It seems a better fit for this particular condition: http://en.wikipedia.org/wiki/Java_Logging_Frameworks#Level What do you think? Jonathan |
From: Sundling, P. <Pau...@sm...> - 2009-04-11 02:31:43
|
It seems like it would be nice to have a convenience method to set multiple bean processors on JsonConfig. There are ways to do so in Spring using FactoryBean and Initializing bean, even though there is not a normal setter like my convenience method below. If it's not deemed generally useful, it could be added to the JsonView for json-lib-ext-spring instead. Here's the jdk15 version of what I'm thinking: public void setJsonBeanProcessors(Map<Class, JsonBeanProcessor> jsonBeanProcessors) { Set<Class> classes = jsonBeanProcessors.keySet(); for (Iterator<Class> iterator = classes.iterator(); iterator.hasNext();) { Class target = iterator.next(); registerJsonBeanProcessor(target, jsonBeanProcessors.get(target)); } } Then a convenience method coupld be added to delegate this in JsonView to it's JsonConfig. What do you think? Paul Sundling |
From: Ronald R. D. <ron...@gm...> - 2009-03-13 14:30:23
|
I figured out what it is and as far as I am concerned it is broken in the JSON. What was happening is that I had spaces: at the beginning of the JSON string. So for example, it looked like: { "node" : but if I changed it to be: { "node" : Then it worked. Now, I just need to understand how to deal with the parsed stream. I tried the following: // parse the JSON response object: json.responseData.each { println " ${it}" } I also tried: // parse the JSON response object: json.responseData.node.each { println " ${it}" } But I get back NULL data both cases. Thoughts? -- Ron DiFrango http://rdifrango.blogspot.com/ On Fri, Mar 13, 2009 at 9:59 AM, Ronald R. DiFrango <ron...@gm...> wrote: > All, > > I am attempting to do the following with Groovy: > > http.request( GET, JSON ) { > url.query = [ > sourceName:'avm://portal--admin/-1;www;avm_webapps;ROOT;DCP_4963.JPG', > destName:'HHMI Documents/images', name:'ronCopy.jpg', remove:'false' ] > > requestContentType : JSON > > // response handler for a success response code: > response.success = { resp, json -> > println resp.statusLine > > // parse the JSON response object: > json.responseData.results.each { > println " ${it.titleNoFormatting} : ${it.visibleUrl}" > } > } > > // handler for any failure status code: > response.failure = { resp -> > println "Unexpected error: ${resp.statusLine.statusCode} : > ${resp.statusLine.reasonPhrase}" > } > } > > The response JSON looks like the following: > > { "node" : > { > "projectOverviewLocation" : > "workspace://SpacesStore/d83b8a9b-8685-40d4-b045-5def043b85a5" > } > } > > > Which to me looks like valid JSON, but I get the following exception: > > Exception thrown: Invalid JSON String > > net.sf.json.JSONException: Invalid JSON String > at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:143) > at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:103) > at net.sf.json.groovy.JsonSlurper.parseText(JsonSlurper.java:78) > at groovyx.net.http.ParserRegistry.parseJSON(ParserRegistry.java:185) > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:461) > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:407) > at groovyx.net.http.HTTPBuilder.request(HTTPBuilder.java:360) > at ConsoleScript52.run(ConsoleScript52:9) > > Any reason why that might be occurring? > > -- > Ron DiFrango > http://rdifrango.blogspot.com/ > |