0
我有一個基類泛型泛型類型屬性和幾個類繼承它。類似的東西:爲什麼澤西拒絕編組泛型?
public abstract class BaseClass<T extends Number> {
@XmlAnyElement
public T getId() { return id; }
private T id ; // init for hibernate bug workaround
.....
}
@XmlRootElement
public class A extends BaseClass<Integer> {
private String name;
private String error;
private String url;
public String getError() { return error; }
public void setError(String error) { this.error = error; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public void setUrl(String url) { this.url = url; }
public String getUrl() { return url; }
}
當新澤西試圖編組它拋出:
javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: unable to marshal type "java.lang.Integer" as an element because it is missing an @XmlRootElement annotation]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:318)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:172)
at com.sun.jersey.json.impl.JSONMarshallerImpl.marshal(JSONMarshallerImpl.java:94)
at com.sun.jersey.json.impl.BaseJSONMarshaller.marshallToJSON(BaseJSONMarshaller.java:103)
at com.sun.jersey.json.impl.BaseJSONMarshaller.marshallToJSON(BaseJSONMarshaller.java:91)
......
我XmlRootElement將註釋不能添加到整數,所以我應該怎麼辦?
這是在服務器端還是在客戶端?你能顯示資源/客戶端代碼嗎? –