How to map selected fields from JSON to Java Object using gson -


i'm using gson map json on java object. have json looks similar example below

{     "meta": {         "status": 200,         "msg": "ok"     },     "response": {         "blog": {             "title": "we have munchies.",             "name": "wehavethemunchies",             "posts": 10662,             "url": "http://wehavethemunchies.tumblr.com/",             "updated": 1415895690,             "description": "<p>if of have tasty recipes wanna share click submit~ if owner of 1 of images , wish have removed please message , remove quickly. sorry inconvenience. </p>\n\n<p> if tagged <strong>recipe</strong>, can click through photos link recipe. if flickr image, click through flickr image link directly recipe.\n<p><strong>here our popular tags:</strong><p>\n\n<p><a href=\"http://wehavethemunchies.tumblr.com/tagged/munchies\">got munchies?</a>\n<p><a href=\"http://wehavethemunchies.tumblr.com/tagged/recipe\">recipe</a>\n<p><a href=\"http://wehavethemunchies.tumblr.com/tagged/pizza\">pizza</a>\n<p><a href=\"http://wehavethemunchies.tumblr.com/tagged/breakfast\">breakfast</a>\n<p><a href=\"http://wehavethemunchies.tumblr.com/tagged/lunch\">lunch</a>\n<p><a href=\"http://wehavethemunchies.tumblr.com/tagged/dessert\">dessert</a>\n<p><a href=\"http://wehavethemunchies.tumblr.com/tagged/chocolate\">chocolate</a>\n<p><a href=\"http://wehavethemunchies.tumblr.com/tagged/nutella\">nutella</a>\n<p><a href=\"http://wehavethemunchies.tumblr.com/tagged/vegan\">vegan</a>\n<p>\n<small>-4/13/09</small>",             "is_nsfw": false,             "ask": true,             "ask_page_title": "ask me anything",             "ask_anon": false,             "submission_page_title": "submit heart's content~",             "share_likes": false         }     } } 

let's want map selected fields, title , description blog section. so, i've created java class handles request , creates blog object, has 2 fields, representing fields in json, want map

import java.io.serializable;  import org.json.jsonobject;  import com.google.gson.gson;  public class homeresponse implements serializable{      public blog blog;      public static homeresponse fromjsonobject(jsonobject jsonobject){         gson gson = new gson();         return gson.fromjson(jsonobject.tostring(), homeresponse.class);     }  } 

object on want map json:

import java.io.serializable;  import com.google.gson.annotations.serializedname;  public class blog implements serializable{      public string title;     public string description; } 

my question is: can such way? without creating other fields in json, , ommitting "nodes" don't need meta etc.? or need create objects fields, in json i'm acquiring, if not use need them in code?

yes okay omit properties wish ignore.

as matter of facts, if don't need value, shouldn't include property it, offer better performance if anything.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -