I am writing a few Struts2 Rest controllers and it seems that the show() and view() method will be returning two different types of models. Since implementing ModelDriven needs to be typed, I have been setting the type to <Object>
. It seems like there is a better way to do this. Here is a bit of pseudo-code to demonstrate my issue.
public class SomeController implements ModelDriven<Object> {
Object model;
public HttpHeaders show() {
// return a single item from the index() list
model = new SingleItem();
}
public HttpHeaders index() {
// return a list of all items
model = new List<SingleItem>();
}
public Object getModel() {
return model;
}
}
Notice that there are two different types to model, and therefore ModelDriven<Object>
must be used.