I want to get at an actual instance of a domain object. That is, I need to serialize the object, and I'm trying to use the domain object on two sides of an httpinvoker
chain. Is there a way to get a fully-loaded domain object that doesn't have any grails wiring, so that I can serialize it?
We do GrailsHibernateUtil.unwrapIfProxy(obj)
. It won't get rid of Grails injected methods and such - only of Hibernate/GORM proxy, but it should be sufficient.
edit:
implements Serializable
?grails console
on a small domain class:.
import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil
import com.somegroup.domain.*
def loc = SomeDomainClass.get(1)
loc = GrailsHibernateUtil.unwrapIfProxy(loc)
ByteArrayOutputStream bos = new ByteArrayOutputStream()
ObjectOutput out = new ObjectOutputStream(bos)
out.writeObject(loc)
byte[] yourBytes = bos.toByteArray()