Re: [json-lib-user] Default values when converting from Java beans to JSON objects
Brought to you by:
aalmiray
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/ |