Out with (JSON Serializer) and In With GSON
So as many of you know, we worth a lot with Spring MVC (2.5 and up) and utilize the RESTful-ness of Spring quite often. Many times we have also needed to simply respond with JSON for AJAX calls and remote calls. For this, FlexJson works pretty well. I haven’t had much to complain about until I ran into a limitation this week.
Apparently FlexJson doesn’t really handle next objects or List<>’s very well. Matter of fact I found it almost impossible to get the result I was looking for even after using their “include()” method to added in different object properties.
After toying around in a couple forums I finally stumbled upon someone mentioning Gson. Gson is now my favorite thing for this week
!!!
Implementing GSON was simple.
// Initialize Gson
Gson serializer = new Gson();
// Serialize almost any object.. POOF, done!
String jsonString = serializer.toJson(object);
Simple huh? Have fun with Gson, and comment any tips or tricks you have for Json API’s!
Related Posts
7 Awesome New Features in dotCMS 1.9
DotCMS 1.9 will be a monumental update to the current 1.7 version of the CMS project. While 1.7 was and still is an outstanding platform, one can easily see why 1.9 will light the CMS world on fire. I have compile a list of my top 10 favorite dotCMS features in 1.9, enjoy, and feel free to share you're in the comments.
Read moreGoogle Wave Turns 1 Year Old
Google Wave, Happy Birthday. I still have not figured out how you can fit into my daily life, but I'm glad you're here.
Read more