tag:blogger.com,1999:blog-5325426185501267599.post1318423058536949552..comments2023-05-14T04:10:24.239-05:00Comments on Programmer Bruce: Gson v Jackson - Part 1Bruce Colemanhttp://www.blogger.com/profile/03248355056606365506noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-5325426185501267599.post-46423732642781736862013-09-08T23:42:46.158-05:002013-09-08T23:42:46.158-05:00With a release of Gson newer than was available wh...With a release of Gson newer than was available when this article was written, this assertion may be correct. I haven't tested it out, yet.<br /><br />With previous releases of Gson, using HashMap.class (or any other Map implementation) as the deserialization type was problematic. In this article, I see that I maybe didn't expand on why this approach didn't work well with Gson, at the time.ProgrammerBrucehttps://www.blogger.com/profile/17099745653456550599noreply@blogger.comtag:blogger.com,1999:blog-5325426185501267599.post-78190888981561631642013-09-08T22:43:45.094-05:002013-09-08T22:43:45.094-05:00Thanks Bruce, this is a great post as usual. Cheer...Thanks Bruce, this is a great post as usual. Cheers!Anonymoushttps://www.blogger.com/profile/16141388907060749402noreply@blogger.comtag:blogger.com,1999:blog-5325426185501267599.post-21325907706742353372012-12-10T23:29:54.260-06:002012-12-10T23:29:54.260-06:00Making a Map from gson is so much easier then that...Making a Map from gson is so much easier then that mammoth code you have there<br /><br />Gson g = new Gson();<br />Map result = g.fromJson("{"a":"b"}, HashMap.class);<br /><br />that's pretty much the same as Jackson<br /><br />and it does use sensible java classes (from my quick checking)Anonymoushttps://www.blogger.com/profile/01262097330851097007noreply@blogger.comtag:blogger.com,1999:blog-5325426185501267599.post-37718546304695346352012-08-19T09:57:16.318-05:002012-08-19T09:57:16.318-05:00Thanks, very clear comparison.
It is important t...Thanks, very clear comparison. <br /><br />It is important to note that though deserialization of inner classes works, the most important property of inner classes fails: It will not be created inside the outer object, but inside null, meaning that calling b.getParent in the following code will return null. <br /><br />This means inner classes are now just confusing versions of static nested classes.<br /><br />I have only tested this when letting Gson do the initialization of the inner object as well, it might work fine in the example in the article, but that is not an option when using lists of unknown length.<br /><br /> class A <br /> { <br /> public String a = "AAA";<br /> public List<B> bs;<br /> public class B {<br /> public String b = "BBB";<br /> /** This will return null if the object was deserialized by Gson */<br /> public A getParent() {<br /> return A.this<br /> }<br /> } <br /> }Anonymoushttps://www.blogger.com/profile/11810589112523737516noreply@blogger.com