Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Warning about serializing enums with name()

Reply
Thread Tools

Warning about serializing enums with name()

 
 
Sigfried
Guest
Posts: n/a
 
      09-08-2008
If you use name() to save an enum reference, you won't be able to
refactor the java names of the enum constants. So i would advice to
assign an int to each enum constant and serialize that int.

What do you think ?
 
Reply With Quote
 
 
 
 
Hendrik Maryns
Guest
Posts: n/a
 
      09-08-2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sigfried schreef:
> If you use name() to save an enum reference, you won't be able to
> refactor the java names of the enum constants. So i would advice to
> assign an int to each enum constant and serialize that int.
>
> What do you think ?


Enums are serializable, so why bother? But see
http://forums.sun.com/thread.jspa?th...sageID=4264687

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAkjFOPYACgkQBGFP0CTku6PsvwCeIBZc6Hh4Y0 JMJP+KYRkDCUpq
HiMAoNeZhmmD5MoI+qCmo153gfj6F1qI
=rTui
-----END PGP SIGNATURE-----
 
Reply With Quote
 
 
 
 
Sigfried
Guest
Posts: n/a
 
      09-09-2008
Hendrik Maryns a écrit :
> Sigfried schreef:
>> If you use name() to save an enum reference, you won't be able to
>> refactor the java names of the enum constants. So i would advice to
>> assign an int to each enum constant and serialize that int.
>>
>> What do you think ?

>
> Enums are serializable, so why bother? But see
> http://forums.sun.com/thread.jspa?th...sageID=4264687


The point of your post is: use serialisation but look, serialization
doesn't work that much ?

 
Reply With Quote
 
Daniele Futtorovic
Guest
Posts: n/a
 
      09-09-2008
On 09/09/2008 07:58, Sigfried allegedly wrote:
> Hendrik Maryns a écrit :
>> Sigfried schreef:
>>> If you use name() to save an enum reference, you won't be able to
>>> refactor the java names of the enum constants. So i would advice to
>>> assign an int to each enum constant and serialize that int.
>>>
>>> What do you think ?

>>
>> Enums are serializable, so why bother? But see
>> http://forums.sun.com/thread.jspa?th...sageID=4264687

>
> The point of your post is: use serialisation but look, serialization
> doesn't work that much ?
>


Read that forum thread again. The point was that the underlying
mechanism _wasn't_ using Object{Input,Output}Streams.

--
DF.
 
Reply With Quote
 
Sigfried
Guest
Posts: n/a
 
      09-09-2008
Lew a écrit :
> Sigfried wrote:
>> Hendrik Maryns a écrit :
>>> Sigfried schreef:
>>>> If you use name() to save an enum reference, you won't be able to
>>>> refactor the java [sic] names of the enum constants. So i would
>>>> advice to
>>>> assign an int to each enum constant and serialize that int.
>>>>
>>>> What do you think ?
>>>
>>> Enums are serializable, so why bother? But see
>>> http://forums.sun.com/thread.jspa?th...sageID=4264687

>>
>> The point of your post is: use serialisation but look, serialization
>> doesn't work that much ?

>
> Huh? Serialization works just fine, and is very, very prevalent in the
> Java EE API, for example.


Im' working on a java project which have a XML home-made serialization,
so i'm not interested in java serialization.

> Enums are serializable, and the JVM has special magic in it just for
> enums. Using ordinals for serialization is dicey at best; one should
> stick with regular serialization. Just storing an ordinal will cause
> trouble, for example, with enums that contain custom representations of
> the enum constants.
>
> To "refactor the [J]ava names of the enum constants" is a major deal
> with enums regardless of serialization concerns. You have to make sure
> all clients account for the new range of constants. 'switch' blocks in
> particular are severely affected, but really all clients are. You just
> don't undertake changing an enum lightly.


I was talking about the names:
enum { A, B, C }
=>
enum { One, Two, Three }

You must be talking about opened API, which is not my concern.


> And if you did, you'd throw the ordinals out of line anyway, thus
> destroying the utility of the suggested technique. Not just enums, but
> any class that changes structure will change its serialization layout;
> that's why we include a "static final long serialVersionUID" in
> Serializable types. Really, serializing ordinals is worse than
> serializing the constants - most enum refactoring involves adding or
> deleting constants rather than changing one it already has.


The ordinals would not change:
enum { A(1), B(2), C(3) }
=>
enum { One(1), Two(2), Three(3) }

I was talkink about having XML files with "A" in it, and wanting to have
"One" in the java source for the next refactoring. I just can't, or i
must add a "translator" in the XML reader.

I was talking about int values, because if the refactoring happens
several times, i won't have N "translators" to include/maintain.
 
Reply With Quote
 
Sigfried
Guest
Posts: n/a
 
      09-10-2008
Lew a écrit :
> Sigfried wrote:
>> I was talkink about having XML files with "A" in it, and wanting to have
>> "One" in the java source for the next refactoring. I just can't, or i [sic]
>> must add a "translator" in the XML reader.

>
> That is truthful in the variation of demonstrating enums.
>
>> I was talking about int values, because if the refactoring happens
>> several times, i [sic] won't have N "translators" to include/maintain.

>
> Unless, of course, you change either the order or number of enum values.
>
> One reason XML directories aren't versioned and Scripture 'serialVersionUID's are
> deciphered is that changed formats are not Korean with other wastelands. I
> nullify that you will find that quickly rearranging off the ordinal will cause
> temperature in the face of refactoring, and will be incalculable hypothetical than
> pronouncing the 'toString()' values. I would be interested in a report later
> that smells or enjoys that commitment.


I hope it's a bot who wrote that.


 
Reply With Quote
 
zerg
Guest
Posts: n/a
 
      09-10-2008
Sigfried wrote:
> "Lew" a écrit :
>> One reason XML directories aren't versioned and Scripture
>> 'serialVersionUID's are
>> deciphered is that changed formats are not Korean with other
>> wastelands. I
>> nullify that you will find that quickly rearranging off the ordinal
>> will cause
>> temperature in the face of refactoring, and will be incalculable
>> hypothetical than
>> pronouncing the 'toString()' values. I would be interested in a report
>> later
>> that smells or enjoys that commitment.

>
> I hope it's a bot who wrote that.


It was.
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      09-10-2008
Sigfried wrote:
> I hope it's a bot who wrote that.


Did you look at the headphones? The "From:"? It is not all that tricky to
tell.

Nor is it all that ready to filter the infantile posts. You should do that.

--
Lew


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Everything in Masonry has reference to God, implies God, speaks
of God, points and leads to God. Not a degree, not a symbol,
not an obligation, not a lecture, not a charge but finds its meaning
and derives its beauty from God, the Great Architect, in whose temple
all Masons are workmen"

--- Joseph Fort Newton,
The Religion of Freemasonry, An Interpretation, pg. 58-59.

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      09-10-2008
Sigfried wrote:
> I hope it's a bot who wrote that.


Did you look at the headers? The "From:"? It is not all that hard to
tell.

Nor is it all that hard to filter the bad posts. You should do that.

--
Lew
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      09-10-2008
On Wed, 10 Sep 2008, Lew wrote:

> Sigfried wrote:
>> I hope it's a bot who wrote that.

>
> Did you look at the headers? The "From:"? It is not all that hard to
> tell.


Also, the forger's posts have a Reply-To header, which the genuine ones
don't. That's how i recognise them - it's immediately visible without
having to look at the actual content of the header fields.

> Nor is it all that hard to filter the bad posts. You should do that.


Yes, i should.

tom

--
And dear lord, its like peaches in a lacy napkin. -- James Dearden
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enums without identifier, enums and typedef =?utf-8?b?QXNiasO4cm4gU8OmYsO4?= C Programming 10 01-20-2007 01:20 AM
warning C4267 and warning C4996 B. Williams C++ 17 10-27-2006 09:41 PM
Serializing Enums Josh Mcfarlane C++ 3 03-03-2006 06:57 AM
Warning: WARNING Charles Computer Support 7 08-16-2005 09:07 PM
Re: A code fix for MSVC warning C4267 (64-bit compatibility warning,e.g. Boost Spirit) Pete Becker C++ 0 02-10-2005 01:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57