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?