<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: Object serialization in groovy</title>
	<atom:link href="http://satish.name/?feed=rss2&#038;p=66" rel="self" type="application/rss+xml" />
	<link>http://satish.name/?p=66</link>
	<description>{:name =&#62; 'Satish Gunnu', :profession =&#62; 'Software Engineer', :interests =&#62; 'Ruby, Groovy, Java'}</description>
	<pubDate>Tue, 07 Sep 2010 00:21:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Object serialization in groovy &#124; Jiramot.info</title>
		<link>http://satish.name/?p=66&cpage=1#comment-1040</link>
		<dc:creator>Object serialization in groovy &#124; Jiramot.info</dc:creator>
		<pubDate>Wed, 18 Mar 2009 04:13:14 +0000</pubDate>
		<guid isPermaLink="false">http://satish.name/?p=66#comment-1040</guid>
		<description>[...] Source: satish.name [...]</description>
		<content:encoded><![CDATA[<p>[...] Source: satish.name [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edgar</title>
		<link>http://satish.name/?p=66&cpage=1#comment-863</link>
		<dc:creator>Edgar</dc:creator>
		<pubDate>Tue, 24 Feb 2009 12:04:22 +0000</pubDate>
		<guid isPermaLink="false">http://satish.name/?p=66#comment-863</guid>
		<description>Oh, just to clarify why it didn't work. ObjectInputStream uses the last used ClassLoader in the JVM. In my situation, this appearantly is NOT the same loader as Groovy uses to load my groovybean.
One other thing: keep in mind that the serialVersionUID changes every time you compile, even if the bean did not change! I'm using this for temporary caching database output for development purpose (offload the database server). Might be better not to do that and use a Java bean instead to prevent the serialVersionUID from changing every time.</description>
		<content:encoded><![CDATA[<p>Oh, just to clarify why it didn&#8217;t work. ObjectInputStream uses the last used ClassLoader in the JVM. In my situation, this appearantly is NOT the same loader as Groovy uses to load my groovybean.<br />
One other thing: keep in mind that the serialVersionUID changes every time you compile, even if the bean did not change! I&#8217;m using this for temporary caching database output for development purpose (offload the database server). Might be better not to do that and use a Java bean instead to prevent the serialVersionUID from changing every time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edgar</title>
		<link>http://satish.name/?p=66&cpage=1#comment-862</link>
		<dc:creator>Edgar</dc:creator>
		<pubDate>Tue, 24 Feb 2009 11:54:00 +0000</pubDate>
		<guid isPermaLink="false">http://satish.name/?p=66#comment-862</guid>
		<description>This didn't work for me. I see the Groovy API is now extended with an extra ClassLoader parameter for withObjectInputStream, but it's not implemented in the version I'm using (WebSphere sMash). As the sollution on the groovy JIRA says ( http://jira.codehaus.org/browse/GROOVY-1627 ), I ended up extending ObjectInputStream (as Java class), for overriding resolveClass:

[code]public class GroovyObjectInputStream extends ObjectInputStream {

	private ClassLoader myClassLoader;

	public GroovyObjectInputStream(ClassLoader myClassLoader) throws IOException, SecurityException {
		super();
		this.myClassLoader = myClassLoader;
	}

	public GroovyObjectInputStream(InputStream in, ClassLoader myClassLoader) throws IOException {
		super(in);
		this.myClassLoader = myClassLoader;
	}

	@Override
	protected Class resolveClass(ObjectStreamClass desc) throws IOException,
			ClassNotFoundException {
		String name = desc.getName();
	    return Class.forName(name, false, myClassLoader);
	}
}
[/code]

Then use that ObjectInputStream:

[code]def file = new my.utils.GroovyObjectInputStream ( new FileInputStream ( "/home/edgar/objectinput" ), getClass().classLoader )
def input = file.readObject()
[/code]</description>
		<content:encoded><![CDATA[<p>This didn&#8217;t work for me. I see the Groovy API is now extended with an extra ClassLoader parameter for withObjectInputStream, but it&#8217;s not implemented in the version I&#8217;m using (WebSphere sMash). As the sollution on the groovy JIRA says ( <a href="http://jira.codehaus.org/browse/GROOVY-1627" rel="nofollow">http://jira.codehaus.org/browse/GROOVY-1627</a> ), I ended up extending ObjectInputStream (as Java class), for overriding resolveClass:</p>
<p>[code]public class GroovyObjectInputStream extends ObjectInputStream {</p>
<p>	private ClassLoader myClassLoader;</p>
<p>	public GroovyObjectInputStream(ClassLoader myClassLoader) throws IOException, SecurityException {<br />
		super();<br />
		this.myClassLoader = myClassLoader;<br />
	}</p>
<p>	public GroovyObjectInputStream(InputStream in, ClassLoader myClassLoader) throws IOException {<br />
		super(in);<br />
		this.myClassLoader = myClassLoader;<br />
	}</p>
<p>	@Override<br />
	protected Class resolveClass(ObjectStreamClass desc) throws IOException,<br />
			ClassNotFoundException {<br />
		String name = desc.getName();<br />
	    return Class.forName(name, false, myClassLoader);<br />
	}<br />
}<br />
[/code]</p>
<p>Then use that ObjectInputStream:</p>
<p>[code]def file = new my.utils.GroovyObjectInputStream ( new FileInputStream ( &#8220;/home/edgar/objectinput&#8221; ), getClass().classLoader )<br />
def input = file.readObject()<br />
[/code]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: เกรลส์ หกสิบหก » เทคนิคการทำ object serialization ใน Groovy</title>
		<link>http://satish.name/?p=66&cpage=1#comment-783</link>
		<dc:creator>เกรลส์ หกสิบหก » เทคนิคการทำ object serialization ใน Groovy</dc:creator>
		<pubDate>Sun, 01 Feb 2009 11:36:25 +0000</pubDate>
		<guid isPermaLink="false">http://satish.name/?p=66#comment-783</guid>
		<description>[...] จาก http://satish.name/?p=66 [...]</description>
		<content:encoded><![CDATA[<p>[...] จาก <a href="http://satish.name/?p=66" rel="nofollow">http://satish.name/?p=66</a> [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
