Posts

Gson's missing get element function - Part I

The Gson missing recursive get function. One of the issues with the current get function that is available is that it only search’s top-level entry key for the value that is passed in. Example JsonObject result; // json object for the preview below If a result.get(“username”) is done the following set will return null because as I have said above the inbuilt get function only search top level element you wish to find. The following values exists in the top-level [“result”, “error”, “id”] the inner elements will not be searched which is part of the flaw / weakness of using the in-built method. A solution to this problem is show below: {     "result" : {         "total_items" : 1 ,         "total_pages" : 1 ,         "items_per_page" : 25 ,         "current_page" : 1 ,    ...

Mocking Ajax with the JQuery Mockjax Library

Unit testing your JavaScript code to ensure everything works according to plan is a very important and tricky business. Properly testing code bits can save you a lot of time and money. This article focuses not on the general topic of unit testing JavaScript, but more specifically unit testing JQuery Ajax functions. HTML File for the Test. <! DOCTYPE HTML > <html>     <head>         <link rel = "stylesheet" href = "lib/qunit.css" type = "text/css" media = "screen" />         <script src = "lib/qunit.js" ></script>         <script src = "lib/jquery-1.7.js" ></script>         <script src = "lib/json2.js" ></script>         <script src = "lib/jquery.mockjax.js" ></script>      ...