2
我有一個具有3個屬性的操作類。我使用Struts2-Json插件來序列化動作類。我能夠序列化字符串selectedCompany按我的預期使用Struts2-Json插件時的Json序列化問題
問題
的人民ArrayList<Person>
屬性序列與空值。我似乎沒有找到我犯了錯誤的地方。
Json_Response:
動作類別:
package json;
import java.util.ArrayList;
import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import dao.DataAccess;
public class Json extends ActionSupport implements Preparable {
private static final long serialVersionUID = -8415223624346993447L;
private ArrayList<String> list;
private String selectedCompany = "Buhin Engineers";
private ArrayList<Person> people;
public ArrayList<String> getList() {
return list;
}
public void setList(ArrayList<String> list) {
this.list = list;
}
public String getSelectedCompany() {
return selectedCompany;
}
public void setSelectedCompany(String selectedCompany) {
this.selectedCompany = selectedCompany;
}
public ArrayList<Person> getPeople() {
return people;
}
public void setPeople(ArrayList<Person> people) {
this.people = people;
}
public String execute(){
list = new ArrayList<String>();
list.add("Yamaha");
list.add("Hero Honda");
return SUCCESS;
}
@Override
public void prepare() throws Exception {
// TODO Auto-generated method stub
populatePeople();
}
private void populatePeople() {
// TODO Auto-generated method stub
DataAccess da = new DataAccess();
setPeople(da.retrievePeople());
}
}
struts.xml中
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="json-default">
<action name="Json" class="json.Json">
<result type="json">
<param name="includeProperties">selectedCompany,people,list</param>
</result>
</action>
</package>
</struts>
可能重複的[Struts 2的JSON豆解析](http://stackoverflow.com/q/17852550/1700321) –