5

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 GsonBuilder().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

ron
  • 450
  • 9
  • 23

1 Answers1

3

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

Sashi Kolli
  • 751
  • 5
  • 6
  • I got this exception The JsonDeserializer StringTypeAdapter failed to deserialized json object {} given the type class java.lang.String – ron Apr 13 '11 at 00:10
  • Did we find the answer ron? Same issue is here. – Sudhir Oct 20 '15 at 13:07