I am working on struts-rest-plugin index
method to return list of my Fruit
objects in xml
or json
format. It works really well.
Model class:
class Fruit {
private String name;
private double price;
// constructor
// getter/setter
// equals and hash method
}
And I want to exclude some of the properties from my model object in xml/json output, say, price. I know I can wrap it with a wrapper class but it seems a bunch of things to do.
What I have tried:
@Results(@Result(name = "success", type = "redirectAction", params = {
"actionName", "fruit"}))
public class FruitController extends ActionSupport implements
ModelDriven<Object> {
private int id;
private Fruit model = new Fruit();
private List<Fruit> list;
private FruitService fruitService = new FruitService();
public void setId(int id) {
this.id = id;
if (id > 0) {
this.model = fruitService.get(this.id);
}
}
public int getId() {
return this.id;
}
public HttpHeaders index() {
list = fruitService.getAll();
return new DefaultHttpHeaders("index").disableCaching();
}
@Override
public Object getModel() {
return (list != null ? list : model);
}
....
}
struts.xml
...
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="rest-default"/>
<constant name="struts.convention.package.locators" value="controller" />
...
<interceptor-ref name="params">
<param name="excludeParams">price</param>
</interceptor-ref>
...
It's not working. Please help. Thanks.