"Serializable" and "Externalizable" only are marker interfaces that
declare that the programmer thinks that his Java Bean is serializable.
Whether or not it is serializable depends on a lot of other factors,
like having a public no-arg constructor, marking all non-serializable
attributes as transient, and so on (= the bean ACTUALLY is serializable,
independend of the declaration using marker interfaces).
Also, if a bean ACTUALLY is serializable, you can serialize it even if
it is NOT marked as "Serializable" or "Externalizable", using
java.bean.XMLEncoder. Using XMLEncoder you can serialize an object
independent of its marker interfaces.
So there is a difference between "the bean ACTUALLY is serializable" and
"the marker interface Serializable is used to declare potential
serializability".
In some places the spec clearly mandates that the object must implement
the Serializable interface. In other places, it just says, the object
must be serializable. As you see, it is a difference.
So what is wanted by the spec? BEEING serializable, or IMPLEMENTING the
Serializable interface, or BOTH?
Thanks
Markus
Lance J. Andersen schrieb:
> I am not sure I understand the question. Something is going to have
> to implement Serializable or Externalizable to be serializable, so I
> am not sure what is not clear in 2.1.4.
>
> Can you give an example?
>
> -l
>
> Mitesh Meswani wrote:
>> Hi Markus,
>>
>> The spec is not very crisp here. But, I would vote to read it as your
>> later interpretation.
>>
>> Thanks,
>> Mitesh
>>
>> Markus KARG wrote:
>>> I have a question how to interprete the EJB 3.0 Persistence
>>> Specification:
>>>
>>> Chapter 2.1.4 "Primary Keys and Entity Identity" says: "The primary
>>> key class must be serializable". Does that mean that it must
>>> implement the Serializable interface, or is it enough to "just" take
>>> care that somebody will be able to serialize and deserialize that
>>> class? With other words, can a user rely on the fact that every
>>> primary key will implement the Serializable interface, or can he
>>> "only" rely on the fact that the primary key physically is
>>> serializable / deserializable?
>>>
>>> Thanks
>>> Markus
>>>
>
--
http://www.xing.com/go/invita/58469