I have the following code and I would to achieve functionality that /getJson will return user object as json and /getJson2 will return user2 as Json object.
@ParentPackage("json-default")
public class JsonAction extends ActionSupport{
private User user = new User("John","Smith");
private User user2 = new User("Smith","John");
public String populate(){
return "populate";
}
@Action(value="/getJson", results = {
@Result(name="success", type="json")})
public String test(){
return "success";
}
@Action(value="/getJson2", results = {
@Result(name="success", type="json")})
public String test2(){
return "success";
}
@JSON(name="user")
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@JSON(name="user2")
public User getUser2() {
return user2;
}
public void setUser2(User user2) {
this.user2 = user2;
}
}
Currently no matter which method I'm calling I'm still getting the following result:
{"user":{"firstName":"John","lastName":"Smith"},"user2":{"firstName":"Smith","lastName":"John"}}
Is it possible?
Update:
I modified the code:
public class JsonAction extends ActionSupport{
private User user = new User("John","Smith");
private User user2 = new User("Smith","John");
public String populate(){
return "populate";
}
@Action(value="/getJson", results = {
@Result(name="success", type="json",params = {
"includeProperties",
"user"})})
public String test(){
return "success";
}
@Action(value="/getJson2", results = {
@Result(name="success", type="json",params = {
"includeProperties",
"user2"})})
public String test2(){
return "success";
}
@JSON(name="user")
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@JSON(name="user2")
public User getUser2() {
return user2;
}
public void setUser2(User user2) {
this.user2 = user2;
}
}
Now I'm getting
{"user":{}}
and
{"user2":{}}