How can I wrap certain values when serializing an object model to JSON with GSON? Example model:
class Order {
Customer cust;
}
class Customer {
String name;
int age;
}
Serializing a Customer would normally yield something like:
{cust:{name:joe, age:21}}
What I would like to do is wrap the Order and Customer values in an additional element with the class name. So the expected JSON would be:
{Order:{cust:Customer:{name:joe, age:21}}}
The actual classes that I'll be serializing could be anything, so I can't hardcode specific properties in a serializer. But I will want to wrap certain properties with their class name.
How can I do this?