Sunday, June 27, 2010

Representing Collections in WSDL and XSDs

Some people like to represent a Collection of elements as a sequence, without an aggregation element. For instance, if I want to return an array of Location object, I return you this:

<getLocations>
   <Location>Roma</Location>
   <Location>New York</Location>
   <Location>Ouagadougou</Location>
<getLocations>

being getLocation the operation name.

I think this sucks, big time.

I would much rather have:

<getLocations>
  <Locations>
      <Location>Roma</Location>
      <Location>New York</Location>
      <Location>Ouagadougou</Location>
   </Locations>
<getLocations>

It makes the XML a lot more readable and easier to manipulate.
You can add extra info by keeping it hierarchically separated from the collection.
Besides, this is the way the default unmarshaling mechanism from Java (EJB) to OSB works for any type of Java Collection - Sets, Lists, Arrays.

No comments: