<?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: 3 ways to serialize Java Enums</title>
	<atom:link href="http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/</link>
	<description>Java, Web 2.0 and other Tech topics</description>
	<lastBuildDate>Thu, 02 Sep 2010 15:16:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Eric Richardson</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-5533</link>
		<dc:creator>Eric Richardson</dc:creator>
		<pubDate>Wed, 28 Apr 2010 18:47:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-5533</guid>
		<description>What problem are you trying to solve by using different approaches?  The loss of a key.
You are trying to prevent unintended disconnect between a key and a value in an off-line data structure (database table or flat file). None of your solutions do that.

It is like taking a foreign key, embedding it in a string and dropping the string in a column.  Later when you return parse the string, extract the key, lookup the key and find you have broken referential integrity you have no one to blame but yourself.

If you are using a database, create a legal value table and put a real foreign key constraint.  XML with a schema can use an enumeration.

Use the right tool for the right job.</description>
		<content:encoded><![CDATA[<p>What problem are you trying to solve by using different approaches?  The loss of a key.<br />
You are trying to prevent unintended disconnect between a key and a value in an off-line data structure (database table or flat file). None of your solutions do that.</p>
<p>It is like taking a foreign key, embedding it in a string and dropping the string in a column.  Later when you return parse the string, extract the key, lookup the key and find you have broken referential integrity you have no one to blame but yourself.</p>
<p>If you are using a database, create a legal value table and put a real foreign key constraint.  XML with a schema can use an enumeration.</p>
<p>Use the right tool for the right job.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leo Hart</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-4125</link>
		<dc:creator>Leo Hart</dc:creator>
		<pubDate>Fri, 22 Jan 2010 14:46:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-4125</guid>
		<description>We use something similar to example 3 with a Hibernate UserType.  Now we have a requirement to create lookups for all our enum values in our database.  Not sure if there&#039;s a simple way to do that...</description>
		<content:encoded><![CDATA[<p>We use something similar to example 3 with a Hibernate UserType.  Now we have a requirement to create lookups for all our enum values in our database.  Not sure if there&#8217;s a simple way to do that&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vineet</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-4101</link>
		<dc:creator>vineet</dc:creator>
		<pubDate>Wed, 20 Jan 2010 01:08:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-4101</guid>
		<description>Jeremy, you have a fair point. I agree that the difference is just one level of indirection, but a very useful one. It moves the persisted value from the &quot;developer space&quot; to &quot;business space&quot;. I think the change in &quot;business-value&quot; will come from business stakeholders and not the developer and that is what makes approach 3 the most robust, at the cost of simplicity. I use approach 3 most of the times, and approach 2 when I am working on a one person project and I know that I will not change the constant name.

I agree that if theoretically enum constant is dramatically changed, then the divergence between enum name and business-value could be confusing. I just think that it is an uncommon case, the more common case is minor tweaks in the name by the developer, adding/removing underscores, uppercase/lowercase/camelcase modifications.</description>
		<content:encoded><![CDATA[<p>Jeremy, you have a fair point. I agree that the difference is just one level of indirection, but a very useful one. It moves the persisted value from the &#8220;developer space&#8221; to &#8220;business space&#8221;. I think the change in &#8220;business-value&#8221; will come from business stakeholders and not the developer and that is what makes approach 3 the most robust, at the cost of simplicity. I use approach 3 most of the times, and approach 2 when I am working on a one person project and I know that I will not change the constant name.</p>
<p>I agree that if theoretically enum constant is dramatically changed, then the divergence between enum name and business-value could be confusing. I just think that it is an uncommon case, the more common case is minor tweaks in the name by the developer, adding/removing underscores, uppercase/lowercase/camelcase modifications.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-4100</link>
		<dc:creator>Jeremy</dc:creator>
		<pubDate>Tue, 19 Jan 2010 23:40:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-4100</guid>
		<description>Your problem with approach 2 above is that a developer could change the name of the enum, from &quot;GREEN&quot; to &quot;Green&quot; in your example.  But surely the same could happen with your preferred &quot;business-value&quot; approach ie. the developer could just as easily change the business-value as he could the enum name?

While approach 3 may give a level of indirection, I think in the long run having a divergence between the enum name and business-value could just end up being more problematic.</description>
		<content:encoded><![CDATA[<p>Your problem with approach 2 above is that a developer could change the name of the enum, from &#8220;GREEN&#8221; to &#8220;Green&#8221; in your example.  But surely the same could happen with your preferred &#8220;business-value&#8221; approach ie. the developer could just as easily change the business-value as he could the enum name?</p>
<p>While approach 3 may give a level of indirection, I think in the long run having a divergence between the enum name and business-value could just end up being more problematic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vineet</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-4096</link>
		<dc:creator>vineet</dc:creator>
		<pubDate>Tue, 19 Jan 2010 16:13:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-4096</guid>
		<description>Rafael, can you elaborate why providing a setter (or mutator) method for colorValue field will break the implementation?</description>
		<content:encoded><![CDATA[<p>Rafael, can you elaborate why providing a setter (or mutator) method for colorValue field will break the implementation?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rafael Alvarez</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-4095</link>
		<dc:creator>Rafael Alvarez</dc:creator>
		<pubDate>Tue, 19 Jan 2010 15:28:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-4095</guid>
		<description>I concur with Joerg that this is the perfect case for the Hibernate UserType. As soon as someone provides a mutator for the colorValue field, hell will break loose.

And that can happen if you want hibernate to use accessors for the attributes instead of modifying directly the fields.</description>
		<content:encoded><![CDATA[<p>I concur with Joerg that this is the perfect case for the Hibernate UserType. As soon as someone provides a mutator for the colorValue field, hell will break loose.</p>
<p>And that can happen if you want hibernate to use accessors for the attributes instead of modifying directly the fields.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vineet</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-4093</link>
		<dc:creator>vineet</dc:creator>
		<pubDate>Tue, 19 Jan 2010 14:25:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-4093</guid>
		<description>Could you describe or provide a use case how approach 3 is error prone.</description>
		<content:encoded><![CDATA[<p>Could you describe or provide a use case how approach 3 is error prone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vineet</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-4092</link>
		<dc:creator>vineet</dc:creator>
		<pubDate>Tue, 19 Jan 2010 14:22:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-4092</guid>
		<description>Using name() has the drawback that I mentioned. If the developer renames the enum constant, you won&#039;t be able to retrieve the old value.</description>
		<content:encoded><![CDATA[<p>Using name() has the drawback that I mentioned. If the developer renames the enum constant, you won&#8217;t be able to retrieve the old value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joerg Wassmer</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-4091</link>
		<dc:creator>Joerg Wassmer</dc:creator>
		<pubDate>Tue, 19 Jan 2010 12:54:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-4091</guid>
		<description>Your approach 3 is pretty error prone. You should use a Hibernate UserType to do the mapping automatically.</description>
		<content:encoded><![CDATA[<p>Your approach 3 is pretty error prone. You should use a Hibernate UserType to do the mapping automatically.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chandra</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-4090</link>
		<dc:creator>chandra</dc:creator>
		<pubDate>Tue, 19 Jan 2010 12:50:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-4090</guid>
		<description>good 1</description>
		<content:encoded><![CDATA[<p>good 1</p>
]]></content:encoded>
	</item>
</channel>
</rss>
