Skip to content

Instantly share code, notes, and snippets.

@kknd22
Last active August 29, 2015 14:00
Show Gist options
  • Save kknd22/43087a31701ed68fb3ab to your computer and use it in GitHub Desktop.
Save kknd22/43087a31701ed68fb3ab to your computer and use it in GitHub Desktop.
register for hibernate proxy gson factory adapter
/**
* in grails-app/resource/spring/resource.groovy
* beans = {
* hibernateProxyAdapterFactory(hbadapter.HibernateProxyAdapterFactory)
* }
*
*/
package hbadapter;
import org.hibernate.proxy.HibernateProxy;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
public class HibernateProxyAdapterFactory implements TypeAdapterFactory {
public TypeAdapter create(Gson gson, TypeToken type) {
return (HibernateProxy.class.isAssignableFrom(type.getRawType()) ? new HibernateProxyTypeAdapter(gson) : null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment