Skip to main content

Why are collections serialized the way they are?

3 replies [Last post]
jemiller1
Offline
Joined: 2005-01-27
Points: 0

I've noticed that if I have a collection like following,

List persons = new ArrayList();

it gets serialized like this,

...
...
...

I've noticed that this is different than how .NET serializes collections which is like,

...
...
...

The later is what I would have expected it to look like. Anyone know why the JAXB and .NET folks didn't work together and decide on a standard way to do this?

It would be nice to be able to serialize an object in .NET using XmlSerializer and deserialize it in Java using JAXB, or vice versa.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jemiller1
Offline
Joined: 2005-01-27
Points: 0

Thanks, much appreciated. I played around with the XmlElementWrapper previously, but, I didn't know about xmlElement.

moshee
Offline
Joined: 2006-08-22
Points: 0

You can achive the exact seralization like .NET with JAXB by using the @XmlElementWrapper(name="persons") and @xmlElement(name=person) over the collection.

kohsuke
Offline
Joined: 2003-06-09
Points: 0

Correct.