I am trying to serialize hibernate objects using gson. When I do, I get something like this:
User Object with Embedded Address Object
{ "userName" : "melchoir",
"address" : {}
}
That's cool and all, but I want something simpler. I want a more accurate representation of the database object. Specifically, I want to see the foreign key for the address rather than the actual address object. I want something like this:
User Object with Foreign Key
{"userName" : "melchoir",
"addressId" : 3
}
Does anyone know how I can go about getting the second example out of gson and hibernate? I should point out that the hibernate objects have already been loaded. I cannot easily make another hibernate session with different configuration options just to satisfy this. I need a solution which rests with gson.