我正在使用下面的代码,
String companyString= gson.toJson( "Here - List of objects converted to string" );
List<SExecutive> sExecutiveList = gson.fromJson( companyString,
new TypeToken<List>()
{
}.getType() );
上面的代码在运行时没有错误,它生成了sExecutiveList。但是当我在列表中使用对象时,它会抛出错误,
java.lang.ClassCastException: java.lang.Object cannot be cast to com.deloitte.iq.data.beans.solr.SExecutive
at com.deloitte.iq.data.services.solr.test.CompExecutivesDeltaTest.testSolrData(CompExecutivesDeltaTest.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
请帮助,我的SExecutive课程看起来像,
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class SExecutive implements Serializable {
/**
*
*/
private static final long serialVersionUID = -2008257983505376174L;
private String firstName;
private String middleName;
private String lastName;
private String suffix;
private String fullName;
private String execCode;
private String email;
private String jobTitle;
private String companyName;
private String companyCode;
private SAddress address;
private Set<String> jobTitlesSet = new HashSet<String>();
private String phoneNumber;
private List<String> execDetailsReferences = new ArrayList<String>();
private boolean director;
private ExecutiveLevel execLevel;
private List<ExecutiveFunction> execFunctions = new ArrayList<ExecutiveFunction>();
private String changeFlag;
public SExecutive(){}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getCompanyCode() {
return companyCode;
}
public void setCompanyCode(String companyCode) {
this.companyCode = companyCode;
}
public SAddress getAddress() {
return address;
}
public void setAddress(SAddress address) {
this.address = address;
}
public Set<String> getJobTitlesSet() {
return jobTitlesSet;
}
public void setJobTitlesSet(Set<String> jobTitlesSet) {
this.jobTitlesSet = jobTitlesSet;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getExecCode() {
return execCode;
}
public void setExecCode(String execCode) {
this.execCode = execCode;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getJobTitle() {
return jobTitle;
}
public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}
public List<String> getExecDetailsReferences() {
return execDetailsReferences;
}
public void setExecDetailsReferences(List<String> execDetailsReferences) {
this.execDetailsReferences = execDetailsReferences;
}
public String getMiddleName() {
return middleName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public String getSuffix() {
return suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
public boolean isDirector() {
return director;
}
public void setDirector(boolean director) {
this.director = director;
}
public ExecutiveLevel getExecLevel() {
return execLevel;
}
public void setExecLevel(ExecutiveLevel execLevel) {
this.execLevel = execLevel;
}
public List<ExecutiveFunction> getExecFunctions() {
return execFunctions;
}
public void setExecFunctions(List<ExecutiveFunction> execFunctions) {
this.execFunctions = execFunctions;
}
public String getChangeFlag()
{
return changeFlag;
}
public void setChangeFlag( String changeFlag )
{
this.changeFlag = changeFlag;
}
public static class ExecutiveLevel {
private String title;
private String code;
private String description;
public ExecutiveLevel(){
}
public ExecutiveLevel(String t, String c, String d){
setTitle(t);
setCode(c);
setDescription(d);
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "ExecutiveLevel [title=" + title + ", code=" + code
+ ", description=" + description + "]";
}
@Override
public boolean equals(Object obj){
if(obj instanceof ExecutiveLevel){
ExecutiveLevel eLevel = (ExecutiveLevel) obj;
if(eLevel.getTitle()==null ? this.getTitle()==null : eLevel.getTitle().equals(this.getTitle()))
return true;
}
return false;
}
}
public static class ExecutiveFunction {
private String code;
private String text;
public ExecutiveFunction() {
}
public ExecutiveFunction(String c, String t){
setCode(c);
setText(t);
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
@Override
public String toString() {
return "ExecutiveFunction [code=" + code + ", text=" + text + "]";
}
}
@Override
public String toString()
{
return "SExecutive [firstName=" + firstName + ", middleName="
+ middleName + ", lastName=" + lastName + ", suffix=" + suffix
+ ", fullName=" + fullName + ", execCode=" + execCode
+ ", email=" + email + ", jobTitle=" + jobTitle
+ ", companyName=" + companyName + ", companyCode="
+ companyCode + ", address=" + address + ", jobTitlesSet="
+ jobTitlesSet + ", phoneNumber=" + phoneNumber
+ ", execDetailsReferences=" + execDetailsReferences
+ ", director=" + director + ", execLevel=" + execLevel
+ ", execFunctions=" + execFunctions + ", changeFlag="
+ changeFlag + "]";
}
}
我的companyString看起来如下
["SExecutive [firstName\u003dDavid, middleName\u003dnull, lastName\u003dWehner, suffix\u003dnull, fullName\u003dDavid M Wehner, execCode\u003d113697910, email\u003dnull, jobTitle\u003dChief Financial Officer, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dErskine, middleName\u003dnull, lastName\u003dBowles, suffix\u003dnull, fullName\u003dErskine B Bowles, execCode\u003d21838, email\u003dnull, jobTitle\u003dIndependent Director, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dLori, middleName\u003dnull, lastName\u003dGoler, suffix\u003dnull, fullName\u003dLori D Goler, execCode\u003d75299249, email\u003dnull, jobTitle\u003dVice President-People \u0026 Recruiting, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dYvette, middleName\u003dnull, lastName\u003dLui, suffix\u003dnull, fullName\u003dYvette Lui, execCode\u003d111781291, email\u003dnull, jobTitle\u003dDirector-Global Marketing Solutions, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dSheryl, middleName\u003dnull, lastName\u003dSandberg, suffix\u003dnull, fullName\u003dSheryl Kara Sandberg, execCode\u003d51629450, email\u003dnull, jobTitle\u003dChief Operating Officer \u0026 Director, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dDeborah, middleName\u003dnull, lastName\u003dCrawford, suffix\u003dnull, fullName\u003dDeborah Crawford, execCode\u003d104581673, email\u003dnull, jobTitle\u003dDirector-Investor Relations, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dDavid, middleName\u003dnull, lastName\u003dMarcus, suffix\u003dnull, fullName\u003dDavid A Marcus, execCode\u003d127616183, email\u003dnull, jobTitle\u003dHead-Mobile Messaging, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dNicola, middleName\u003dnull, lastName\u003dMendelsohn, suffix\u003dnull, fullName\u003dNicola Mendelsohn, execCode\u003d117761928, email\u003dnull, jobTitle\u003dVice President-Europe, Middle East \u0026 Africa, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dDavid, middleName\u003dnull, lastName\u003dFischer, suffix\u003dnull, fullName\u003dDavid B Fischer, execCode\u003d77683112, email\u003dnull, jobTitle\u003dVice President-Business \u0026 Marketing Partnerships, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dJason, middleName\u003dnull, lastName\u003dTaylor, suffix\u003dnull, fullName\u003dJason Taylor, execCode\u003d120904969, email\u003dnull, jobTitle\u003dDirector-Infrastructure Foundation, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dTimothy, middleName\u003dnull, lastName\u003dCampos, suffix\u003dnull, fullName\u003dTimothy Campos, execCode\u003d111589204, email\u003dnull, jobTitle\u003dChief Information Officer, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dColin, middleName\u003dnull, lastName\u003dStretch, suffix\u003dnull, fullName\u003dColin Stretch, execCode\u003d118626386, email\u003dnull, jobTitle\u003dSecretary, Vice President \u0026 General Counsel, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dDan, middleName\u003dnull, lastName\u003dRose, suffix\u003dnull, fullName\u003dDan Rose, execCode\u003d58470211, email\u003dnull, jobTitle\u003dVice President-Partnerships, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dCarolyn, middleName\u003dnull, lastName\u003dEverson, suffix\u003dnull, fullName\u003dCarolyn Everson, execCode\u003d97512374, email\u003dnull, jobTitle\u003dVice President-Global Marketing Solutions, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dMark, middleName\u003dnull, lastName\u003dHamilton, suffix\u003dnull, fullName\u003dMark Hamilton, execCode\u003d125035740, email\u003dnull, jobTitle\u003dHead-CEEMEA Marketing Communications, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dDonald, middleName\u003dnull, lastName\u003dGraham, suffix\u003dnull, fullName\u003dDonald E Graham, execCode\u003d38280, email\u003dnull, jobTitle\u003dLead Independent Director, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dJas, middleName\u003dnull, lastName\u003dAthwal, suffix\u003dnull, fullName\u003dJas Athwal, execCode\u003d118113960, email\u003dnull, jobTitle\u003dChief Accounting Officer, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dMichael, middleName\u003dnull, lastName\u003dSchroepfer, suffix\u003dnull, fullName\u003dMichael Todd Schroepfer, execCode\u003d97730131, email\u003dnull, jobTitle\u003dChief Technology Officer \u0026 VP-Engineering, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dAshley, middleName\u003dnull, lastName\u003dZandy, suffix\u003dnull, fullName\u003dAshley Zandy, execCode\u003d110554425, email\u003dnull, jobTitle\u003dHead-Corporate Communications, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dPeter, middleName\u003dnull, lastName\u003dThiel, suffix\u003dnull, fullName\u003dPeter A Thiel, execCode\u003d43952425, email\u003dnull, jobTitle\u003dIndependent Director, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dMarc, middleName\u003dnull, lastName\u003dAndreessen, suffix\u003dnull, fullName\u003dMarc L Andreessen, execCode\u003d42264796, email\u003dnull, jobTitle\u003dIndependent Director, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dChristopher, middleName\u003dnull, lastName\u003dCox, suffix\u003dnull, fullName\u003dChristopher K Cox, execCode\u003d64372848, email\u003dnull, jobTitle\u003dChief Product Officer, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dElliot, middleName\u003dnull, lastName\u003dSchrage, suffix\u003dnull, fullName\u003dElliot Schrage, execCode\u003d41159898, email\u003dnull, jobTitle\u003dVP-Global Communications \u0026 Marketing, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dGary, middleName\u003dnull, lastName\u003dBriggs, suffix\u003dnull, fullName\u003dGary S Briggs, execCode\u003d54600983, email\u003dnull, jobTitle\u003dChief Marketing Officer, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dMarne, middleName\u003dnull, lastName\u003dLevine, suffix\u003dnull, fullName\u003dMarne L Levine, execCode\u003d75594622, email\u003dnull, jobTitle\u003dVice President-Global Public Policy, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dMark, middleName\u003dnull, lastName\u003dZuckerberg, suffix\u003dnull, fullName\u003dMark Elliot Zuckerberg, execCode\u003d544858, email\u003dnull, jobTitle\u003dChairman \u0026 Chief Executive Officer, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dWilmot, middleName\u003dnull, lastName\u003dHastings, suffix\u003dnull, fullName\u003dWilmot Reed Hastings Jr., execCode\u003d11607878, email\u003dnull, jobTitle\u003dIndependent Director, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]","SExecutive [firstName\u003dSusan, middleName\u003dnull, lastName\u003dDesmond-Hellmann, suffix\u003dnull, fullName\u003dSusan D Desmond-Hellmann, execCode\u003d82640911, email\u003dnull, jobTitle\u003dIndependent Director, companyName\u003dnull, companyCode\u003dnull, address\u003dnull, jobTitlesSet\u003d[], phoneNumber\u003dnull, execDetailsReferences\u003d[], director\u003dfalse, execLevel\u003dnull, execFunctions\u003dnull, changeFlag\u003dIS_NEW]"]