2

I have a SOAPAction which returns a list of reports with positions. The positions should be in a certain order: Sorted by their zOrder attribute

Before sending the response the list of positions is sorted:

/*sort the positions in the report before adding it to the list*/
List<Position> orderedPositions = report.getPositions();
Collections.sort(orderedPositions, new Comparator<Position>() {
   @Override
   public int compare(Position position, Position position2) {
      return position.getZOrder().compareTo(position2.getZOrder());
   }
});
report.setPositions(orderedPositions);

I checked that the list is in the correct order and it is.

In the response XML, the elements of the <positions> tag are not in the same order as those in the java object. The elements do not seem to be ordered at all. Here is an excerpt:

<positions>
   <chapter>911</chapter>
   <chapterType>LPK</chapterType>
   <formId>16972704</formId>
   <materialNumber>121</materialNumber>
   <positionID>S16977468</positionID>
   <positionText>-</positionText>
   <positionType>Work</positionType>
   <quantity>9.0</quantity>
   <quantityUnit>h</quantityUnit>
   <serviceReport>16975051</serviceReport>
   <unitPrice>0.0</unitPrice>
   <xmlId>16977468</xmlId>
   <ZOrder>905</ZOrder>
</positions>
<positions>
   <chapter>0</chapter>
   <chapterType>LPK</chapterType>
   <formId>16972704</formId>
   <materialNumber></materialNumber>
   <positionID>S16977469</positionID>
   <positionText></positionText>
   <positionType>Material</positionType>
   <quantity>1.0</quantity>
   <quantityUnit>St</quantityUnit>
   <serviceReport>16975051</serviceReport>
   <unitPrice>0.0</unitPrice>
   <xmlId>16977469</xmlId>
   <ZOrder>1002</ZOrder>
</positions>
<positions>
   <chapter>0</chapter>
   <chapterType>NPK</chapterType>
   <formId>16972704</formId>
   <materialNumber></materialNumber>
   <positionID>S16977470</positionID>
   <positionText></positionText>
   <positionType>Material</positionType>
   <quantity>2.0</quantity>
   <quantityUnit>St</quantityUnit>
   <serviceReport>16975051</serviceReport>
   <unitPrice>0.0</unitPrice>
   <xmlId>16977470</xmlId>
   <ZOrder>1003</ZOrder>
</positions>
<positions>
   <chapter>0</chapter>
   <chapterType>LPK</chapterType>
   <formId>16972704</formId>
   <materialNumber></materialNumber>
   <positionID>S16977471</positionID>
   <positionText></positionText>
   <positionType>Material</positionType>
   <quantity>3.0</quantity>
   <quantityUnit>St</quantityUnit>
   <serviceReport>16975051</serviceReport>
   <unitPrice>0.0</unitPrice>
   <xmlId>16977471</xmlId>
   <ZOrder>1004</ZOrder>
</positions>

How can I get the positions elements in the response XML sorted by their ZOrder attribute?

Micha Roon
  • 3,957
  • 2
  • 30
  • 48
  • The positions are ordered. – Xargos Jul 16 '13 at 07:27
  • I fail to see an order key. But the question is: how can I determine an arbitrary sort order – Micha Roon Jul 17 '13 at 08:24
  • I don't get what you mean by order key. In the code you provided you sort the list according to the ZOrder element, and when you look at the XML, the positions are indeed ordered by that element. – Xargos Jul 17 '13 at 08:30
  • you are correct and everything is actually sorted. but my response array is not sorted correctly. I feel silly and will close the question. Thank you for your time – Micha Roon Jul 17 '13 at 14:35

0 Answers0