Keith,

If I have time, I'll try to whip up something.

-----Original Message-----
From: Keith Visco [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 02, 2002 1:41 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] problems serializing type-safe enumerations



Hi Erik,

I read about this issue in a recent JDC Tech Tips (Java Developer
Connection) newsletter from Sun. I was planning on trying to make the
serialization work properly, however haven't had to much time to look
into it.

I was hoping this issue wouldn't come up so quickly, since I just read
about the problem in the February 5th issue of the JDC Tech Tips.

We'll code up a solution for people using "-type j2" option. Hopefully
in the meantime you don't mind modifying your enumerations until we have
a chance to do it. 

Or if you have a little time and want to try to fix the problem in
Castor itself that would be great for all of us.

Thanks,

--Keith

[EMAIL PROTECTED] wrote:
> 
> Greetings, all.  Thanks for such a great product.
> 
> We are using the SourceGenerator to generate java classes based on a
> schema.  We are using the feature
> that generates a Java type-safe enum pattern from an XML Schema
> enumeration.
> When we serialize those type-safe enum objects (over RMI), we are
> running into problems described in this article
> (http://www.javaworld.com/javaworld/javatips/jw-javatip122.html).
> 
> In short, the == and .equals() don't work after a type-safe
enumeration
> object has been serialized.
> Instead, one object never equals another object.
> 
> Do you have any suggestions?  One option would be to code generate a
> readResolve() method as described in the article.
> 
> Thanks again,
> 
> Erik Ostermueller
> [EMAIL PROTECTED]
> ###################################################
> 
> The following is an exerpt from this article:
> 
> At a minimum, we have to add a readResolve() method and an instance
> field to use as the real instance ID:
> public final class Enum implements java.io.Serializable
> {
> public static final Enum TRUE = new Enum (true);
> public static final Enum FALSE = new Enum (false);
> 
> public String toString ()
> {
> return String.valueOf (m_value).toUpperCase ();
> }
> 
> private Enum (boolean value)
> {
> m_value = value;
> }
> 
> private Object readResolve () throws java.io.ObjectStreamException
> {
> return (m_value ? TRUE : FALSE);
> }
> 
> private boolean m_value;
> 
> } // end of class
> Here, in the readResolve() method, I check the value ID of the
instance
> just created and replace the deserialized instance with one of the
> static objects.
> Unfortunately, many programmers today are unaware they must implement
> readResolve() to perform instance substitution during serialization
> (this feature was not available before Java 2 either). If we don't do
> this, however, we won't get any compiler or runtime errors -- the
> reference comparison will simply fail each time we compare an Enum
value
> against a deserialized Enum instance. Depending on the enumeration's
> size, the amount of work necessary to have a correct and serializable
> typesafe class may be too much compared to the good old "typeunsafe"
> pattern (the standard practice of defining simple-minded sets of
> constants referred to earlier), which lacks this issue.
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to