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,695
  • 16
  • 55
  • 88

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,906
  • 5
  • 45
  • 73
Anantha Sharma
  • 9,920
  • 4
  • 33
  • 35