Re: [json-lib-user] Question about null Number serialization
Brought to you by:
aalmiray
From: Andres A. <aal...@ya...> - 2008-02-05 01:07:33
|
Anil, That is the expected behavior because numbers in JSON can never by null, only objects. It may be a bit confusing at first because numbers in java come in two flavors: primitive and wrappers, wrappers being objects after all. But there is a way to override this behavior, you may register a DefaultValueProcessor to return whatever value (any valid json value that is) that your app requires. 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. ----- Original Message ---- From: Anil Gangolli <an...@bu...> To: jso...@li... Sent: Monday, February 4, 2008 5:04:11 PM Subject: [json-lib-user] Question about null Number serialization Apologies if this is a FAQ, but I tried for some time to find it and couldn't. If I have a bean with a Long or Number property, e.g. class TestBean { private Long number = null; public Long getNumber() { return number; } public void setNumber(Long number) { this.number = number; } } and serialize an instance where the "number" property is null, for example using JSONSerializer.toJSON(new TestBean()).toString() it gives the result {"number":0} and deserializing this gives an instance that is not equal to the original. Is this expected or a bug? I was expecting a serialized form of {"number":null} which, when deserialized does give me an instance equal to the original. --a. -----Inline Attachment Follows----- ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ -----Inline Attachment Follows----- _______________________________________________ json-lib-user mailing list jso...@li... https://lists.sourceforge.net/lists/listinfo/json-lib-user ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ |