XML Serialization

XML Serialization

am 15.04.2008 23:49:33 von tom

OK,

I have an object that I would like to serialize to an XML file. I can do
that successfully, but if I modify the object to have a constructor that
takes parameters, I get the following error message:

Object cannot be serialized because it does not have a parameterless
constructor

While this error message makes perfectly clear what the problem is, I still
don't understand why this is a problem. My google skills seem to be lacking
today too.

Can anybody out there explain why I can't serialize an object to XML if it
has a constructor that has parameters?

Thanks.

RE: XML Serialization

am 16.04.2008 21:16:01 von FamilyTreeMike

I believe it is as simple as "How would the system know which elements to
feed to the constructor?".

By the way, having both an parameterless constructor as well as the one you
want with parameters is permitted.

"Tom" wrote:

> OK,
>
> I have an object that I would like to serialize to an XML file. I can do
> that successfully, but if I modify the object to have a constructor that
> takes parameters, I get the following error message:
>
> Object cannot be serialized because it does not have a parameterless
> constructor
>
> While this error message makes perfectly clear what the problem is, I still
> don't understand why this is a problem. My google skills seem to be lacking
> today too.
>
> Can anybody out there explain why I can't serialize an object to XML if it
> has a constructor that has parameters?
>
> Thanks.
>

Re: XML Serialization

am 16.04.2008 21:25:23 von Michael Justin

> Can anybody out there explain why I can't serialize an object to XML if
> it has a constructor that has parameters?

If there is *only* a constructor that takes parameters, the receiver of
the serialized object will need values for the parameters and pass them
to it in order to create an instance. See the problem?

Best Regards
--
Michael Justin
SCJP, SCJA
betasoft - Software for Delphi™ and for the Java™ platform
http://www.mikejustin.com - http://www.betabeans.de

Re: XML Serialization

am 16.04.2008 21:26:04 von Michael Justin

> Can anybody out there explain why I can't serialize an object to XML if
> it has a constructor that has parameters?

If there is *only* a constructor that takes parameters, the receiver of
the serialized object will need values for the parameters and pass them
to it in order to create an instance. See the problem?

Best Regards


--
Michael Justin
SCJP, SCJA
betasoft - Software for Delphi™ and for the Java™ platform
http://www.mikejustin.com - http://www.betabeans.de

Re: XML Serialization

am 16.04.2008 21:27:49 von Michael Justin

> Can anybody out there explain why I can't serialize an object to XML if
> it has a constructor that has parameters?

If there is *only* a constructor that takes parameters, the receiver of
the serialized object will need values for the parameters and pass them
to it in order to create an instance. See the problem?

Best Regards
--
Michael Justin
SCJP, SCJA
betasoft - Software for Delphi™ and for the Java™ platform
http://www.mikejustin.com - http://www.betabeans.de

Re: XML Serialization

am 16.04.2008 21:30:52 von tom

Ah yes ...

Thanks guys.


"Family Tree Mike" wrote in
message news:8039A762-8494-41AF-9E06-711973EF0703@microsoft.com...
>I believe it is as simple as "How would the system know which elements to
> feed to the constructor?".
>
> By the way, having both an parameterless constructor as well as the one
> you
> want with parameters is permitted.
>
> "Tom" wrote:
>
>> OK,
>>
>> I have an object that I would like to serialize to an XML file. I can do
>> that successfully, but if I modify the object to have a constructor that
>> takes parameters, I get the following error message:
>>
>> Object cannot be serialized because it does not have a parameterless
>> constructor
>>
>> While this error message makes perfectly clear what the problem is, I
>> still
>> don't understand why this is a problem. My google skills seem to be
>> lacking
>> today too.
>>
>> Can anybody out there explain why I can't serialize an object to XML if
>> it
>> has a constructor that has parameters?
>>
>> Thanks.
>>