I need to return a list of ordered String from an ajax Call
my DTO has an attributes sizes which is a list of String values , eg : 36,38,40/46, 46, S, XS, M, L
my comparator and sorting algorithm work well , the list of sizes is well sorted until its converted to json format, i found a totally different order .
@ResponseBody
@RequestMapping(value = PRODUCT_CODE_PATH_VARIABLE_PATTERN + "/crossell", method = RequestMethod.GET)
public ProductData cosselProductDetail(@PathVariable("productCode") final String productCode,
final HttpServletResponse response) throws CMSItemNotFoundException,
UnsupportedEncodingException
{
Collections.sort(sortedSizes,mycomparator);
productData.setSizes(sortedSizes);
return productData;
}
the spring config is the default configuration no thing added or modified .
<!-- activates annotation driven binding -->
<mvc:annotation-driven ignoreDefaultModelOnRedirect="true" validator="validator">
<mvc:message-converters>
<bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
</mvc:message-converters>
</mvc:annotation-driven>
after searching all around , all what i found is the serialisation key config : SORT_PROPERTIES_ALPHABETICALLY , which order the properties not the values.
Thanks