开发者

Gson ignore json field and deserialize

开发者 https://www.devze.com 2023-02-25 12:23 出处:网络
I\'m working with android and gson and i was wondering if i can ignore a field from the webservice. this its my gson object

I'm working with android and gson and i was wondering if i can ignore a field from the webservice.

this its my gson object

Gson gson = new GsonB开发者_JAVA百科uilder().serializeNulls().create();

So what i need is to ignore validator field and deserialize to my custom bean in the following code.

Its any way to do that with gson ?

{ "posts":
  [      

        {
       "username": "John",  
       "message": "I'm back",
       "time": "2010-5-6 7:00:34"
        "validator":[{
                        "prog": "Name1",
                        "name": "Name2",
                        "computername": "Name3",
                        "date": "2010-11-20 19:39:55"
                      }]
        }
      ,

        {
          "username": "Smith",
          "message": "I've been waiting",
          "time": "2010-4-6 10:30:26"
           "validator":[{
                        "prog": "Name1",
                        "name": "Name2",
                        "computername": "Name3",
                        "date": "2010-11-20 19:39:55"
                      }]

       }
]}

Thanks in advance

Cheers


You can call gson.fromJson(inputString, localObject) and if localObject doesn't declare a validator variable, it will just skip it.

0

精彩评论

暂无评论...
验证码 换一张
取 消