Reputation: 593
I'm working on extending a REST API written in Java using the Spring framework, Hibernate ORM and Jackson for JSON (de)serialization.
On a few API calls, I need to return a user's account given a provided value (say, a subscription ID). There are different types of accounts, so a type value is included so the client can determine what kind of account they're dealing with.
In my controller, I pass the provided user ID down to the service call which calls this method:
public Account getAccountBySubscriptionId(long subscriptionId) {
ServiceSubscription subscription = subscriptionDAO.load(subscriptionId);
if(subscription != null) {
return subscription.getAccount();
} else {
return null;
}
}
I would expect this to return JSON similar to this:
{
"type":"account_type_goes_here",
"id":1,
"accountNumber":"100"
}
However, it appears that Hibernate's lazy loading is modifying the type value, as such (note that UserAccount is the class of the object):
{
"type":"UserAccount_$$_javassist_1",
"id":2,
"accountNumber":"37"
}
How could I make Hibernate retain the original value for type instead of modifying it?
Upvotes: 0
Views: 69
Reputation: 253
Are you sure there isn't an error in your logic that's returning the type of the object and not the string value of the type of the account?
Upvotes: 2