My code is something like:
@XmlRootElement
@XmlType(propOrder = {"id", "name", "content", "disclaimer", "buttons"})
public class Product {
private String id;
private String name;
private String content;
private String disclaimer;
private List<ProductButton> buttons = new ArrayList<ProductButton>();}
Service code is:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/GetProduct")
public Response getProduct() {
try {
Product product = generateProductById(productId);
return Response.ok().entity(product).build();
}
catch (Exception e) {
log.error(e.getLocalizedMessage(), e);
return Response.serverError().build();
}
}
However the output json string is not in order.
My expected order is same as my object, however the result is: "name", "id", "content"...
Anyone got idea how i can achieve that?
--------------------------------------Updated--------------------------------
@JsonPropertyOrder({"id", "name", "content", "disclaimer", "buttons"})
public class Product {
private String id;
private String name;
private String content;
private String disclaimer;
private List<ProductButton> buttons = new ArrayList<ProductButton>();}