title: how to serialize domain classes grails
body: <p>I tried to serialize grails domains classes to Maps or similar in order to be able to store it in memcached.</p>
  
  <p>I want to be able to read the objects only, I don't need gorm crud. Only to read them without breaking the kind of interfaces they have.</p>
  
  <p>For instance: I could convert domains to maps, becouse it wouldn't break the interface for access like <code>.&lt;property&gt;</code> or <code>.findall</code> or similar</p>
  
  <p>First I tried to do a manual serialization but it was very error prone. So I needed something more general.</p>
  
  <p>Then I tried to serialize as a map with a grails codec.</p>
  
  <p><a href="https://github.com/dnoseda/domain-to-map-serializer-problem" rel="nofollow">Here is the testing repo.</a></p>
  
  <p><a href="https://gist.github.com/3763113" rel="nofollow">Here is the snippet.</a></p>
  
  <p>But I get StackOverFlowException.</p>
  
  <p>I also tried to mark all the domains as Serializable but I need to reattach every domain when I bring them back from memcached to avoid hibernate errors like org.hibernate.LazyInitializationException: could not initialize proxy - no Session</p>
  
  <p>Do you know a way to achieve this?</p>
  
  <p>Is very frustrating to google search for something like this "storing domain classes in memcached" and find out is not a common problem.</p>