Canonical representation of a class object containing a list element in XML

Posted by dendini on Programmers See other posts from Programmers or by dendini
Published on 2013-10-18T14:24:30Z Indexed on 2013/10/18 16:11 UTC
Read the original article Hit count: 267

Filed under:

I see that most implementations of JAX-RS represent a class object containing a list of elements as follows (assume a class House containing a list of People)

<houses>
  <house>
    <person>
      <name>Adam</name>
    </person>
    <person>
      <name>Blake</name>
    </person>
  </house>
  <house>
  </house>
</houses>

The result above is obtained for instance from Jersey 2 JAX-RS implementation, notice Jersey creates a wrapper class "houses" around each house, however strangely it doesn't create a wrapper class around each person! I don't feel this is a correct mapping of a list, in other words I'd feel more confortable with something like this:

<houses>
  <house>
    <persons>
    <person>
      <name>Adam</name>
    </person>
    <person>
      <name>Blake</name>
    </person>
    </persons>
  </house>
  <house>
  </house>
</houses>

Is there any document explaining how an object should be correctly mapped apart from any opninion?

© Programmers or respective owner

Related posts about Xml