Q:

How to return a json array with struts?

Here is my struts action
@Action("/trylogin")
@ParentPackage("json-default")
@Result(type = "json", params = { "includeProperties", "msg, productsList" })
public class Login extends ActionSupport {

    private static final long serialVersionUID = 1L;
    private String utilisateur;
    private String motdepasse;
    private String msg;
    private ArrayList<Article> productsList = new ArrayList<Article>();

    @Autowired
    private Dao dao;

    public String execute() {

        if (dao.validCredentials(utilisateur, motdepasse)) {
            System.out.println("USER FOUND");
            productsList = dao.fetchProducts();
            msg = "success";
        } else {
            System.out.println("ERREUR");
            msg = "error";
        }
        return ActionSupport.SUCCESS;
    }

public ArrayList<Article> getProductsList() {
    return productsList;
}

public String getMsg() {
    return msg;
}

Here is my ajax post :
$.post({
    url: "trylogin",                        
    data: {                                 
        utilisateur: name,
        motdepasse: password
    }       
}).done(function(data) {                
    console.log(data.productsList.length);
}).fail(function( jqXHR, textStatus ) {     
    console.log("Fail");
})

I'd like to fetch my productsList. In my Action the list is loaded properly. But once I console.log(data.productsList) it's empty.
How should I do to get the productsList from my struts action to my javascript ?
My productsList is a list of objects that has various attributes like name/id/color... 

A:

The parameter includeProperties is a list of regex expressions. When you use a parameter productsList the json  serializer only finds this property, but when goes further and parse it's elements none of them are included. If you use this parameter with the result only properties that match the expressions are included in the json output. 
You need to configure includeProperties in the json result. For example
@Result(type="json", params = {"includeProperties", "msg,
  productsList\\[\\d+\\]\\.id,productsList\\[\\d+\\]\\.name,productsList\\[\\d+\\]\\.color"}) 

Note, that special characters are double escaped.

