Skip to content

Instantly share code, notes, and snippets.

@dtelaroli
Last active August 29, 2015 14:24
Show Gist options
  • Save dtelaroli/4e82ce99d1ed0d7765b5 to your computer and use it in GitHub Desktop.
Save dtelaroli/4e82ce99d1ed0d7765b5 to your computer and use it in GitHub Desktop.
Problema de serialização de Lazy Loading do Hibernate no VRaptor4
import java.lang.reflect.Type;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import org.hibernate.proxy.HibernateProxy;
import com.google.gson.JsonElement;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import br.com.caelum.vraptor.serialization.gson.GsonSerializerBuilder;
@Dependent
public class HibernateProxyJson implements JsonSerializer<HibernateProxy> {
@Override
public JsonElement serialize(HibernateProxy src, Type typeOfSrc, JsonSerializationContext context) {
try {
Object deProxied = src.getHibernateLazyInitializer().getImplementation();
return context.serialize(deProxied);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment