Last active
August 29, 2015 14:24
-
-
Save dtelaroli/4e82ce99d1ed0d7765b5 to your computer and use it in GitHub Desktop.
Problema de serialização de Lazy Loading do Hibernate no VRaptor4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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