SerializedName for a property in a class

154 views
Skip to first unread message

PabloDO

unread,
Nov 4, 2011, 11:34:38 AM11/4/11
to google-gson
Hi, i'm trying to deserialize a json wich this format:
"class1":{
"field_1":"asd"
"field_2":123
"class2":{
"id":12345
}
}

but i don't want to create a class "class2" with only one property, so
i want to indicate to a field id that is class2.id

public class class1(){
@SerializedName("field_1") String field1;
@SerializedName("field_2") int field2;
@SerializedName("class2.id") int id; // This is what i'm trying
to do, but i don't know how to do something like this
}

How can i do this?

Inderjeet Singh

unread,
Nov 5, 2011, 4:35:31 PM11/5/11
to googl...@googlegroups.com
You can write a custom type adapter for Class1 that would map the id field. I dont think there is another way to do this.

Inder
---
My Android App: https://market.android.com/details?id=com.applimobile.spellmeright
Reply all
Reply to author
Forward
0 new messages