2

I have following POJO's

public class Category {
    private Integer id;
    private String title;
    private String description;

    //many more attributes below
}

public class User {
        private Integer id;
        private String name;
        private String address;

           //many more attributes below
    }

public class MyAction extends ActionSupport {

       //list of objects
    List<Category> categories;

       //Complex Map
    private Map<Category, List<User>> categorizedUsers;

       //getters and setters

    @Override
    public String execute() {

        //populate "categories" and "categorizedUsers" with some business logic
        return SUCCESS;  
}
}

I make an AJAX call for this action and expect the data (i.e. "categories" and "categorizedUsers") in JSON format. Struts2 provides us with JSON interceptor where I can specifically filter the parameters to be serailized.

Following is configuration in struts xml file

<action name="mywidget" class="com.struts.action.MyAction">
     <result type="json">
        <param name="includeProperties">
           ^categories\[\d+\]\.id, 
           ^categories\[\d+\]\.title,
        </param>
    </result>
</action>

Both the POJOs contain a lot of attributes, but with "includeproperties", I was able to filter out id and title for each Category in the list.

However for the map key as well as value, I'm unable to apply any such regex pattern to filter out desired attributes. (Lets say for the map key Category, I need id and title, whereas for each Value User, I need to filter out id, name only). Please suggest appropriate regex pattern to be applied on the Map<Category, List<User>>.

Roman C
  • 49,761
  • 33
  • 66
  • 176
hemantvsn
  • 1,316
  • 3
  • 12
  • 24

0 Answers0