0

If I have a class say

class A
{
String field1
String field2
String field3
} 

And I have another class B that contains the following

{
String field1
String field2
} 

There is a byte array of key value pairs, [#maps to field1, #maps to field2] How can I using gson map the byte array to the fields in class A without creating a class B that contains the exact number of fields in the map ?

Can I exclude field3 while deserialization ? How do I do that ?

Phoenix
  • 8,357
  • 16
  • 51
  • 84

1 Answers1

1

The best approach would be to mark field3 as

transient

Gson will not populate (deserialize) its value from the string.. Alternatively, you can use a custom deserializer implementation which would selectively deserialize things. Here is a link for this kind of solution.

giampaolo
  • 6,788
  • 5
  • 43
  • 73
Anantha Sharma
  • 9,450
  • 4
  • 32
  • 35