Re: [json-lib-user] Is it possible to force JSONObject.toBean() throw exceptions on cast issues for
Brought to you by:
aalmiray
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 |