gpt4 book ai didi

java - Jersey 休息服务显示异常 javax.ws.rs.WebApplicationException : javax. xml.bind.MarshalException

转载 作者:行者123 更新时间:2023-11-29 07:54:06 24 4
gpt4 key购买 nike

我正在研究我提到的 Jersey 服务 here当我返回一个 java 对象时它工作正常。后来我试图使 java 对象通用它给出异常javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException

@XmlRootElement
public class AppObject<T> implements Serializable {

private List<T> list;
private String license;

public AppObject() {
list = new ArrayList<T>();

}

public AppObject(List<T> list) {
this.list = list;
}

@XmlAnyElement(lax = true)
public List<T> getList() {
return list;
}

public void setList(List<T> list) {
this.list = list;
}

public String getLicense() {
return license;
}

public void setLicense(String license) {
this.license = license;
}

}

我的服务

@GET
@Produces({MediaType.APPLICATION_XML ,MediaType.APPLICATION_JSON})
@Path("/getreq")
public AppObject<DimRequirement> savePayment() {
AppObject<DimRequirement> appObject = new AppObject<DimRequirement>();
appObject.setLicense("4");
Long clientKey=4L;
List<DimRequirement> dimreqlist = dimRequirementDao.getAllByClientNIsCurrent(clientKey);
appObject.setList(dimreqlist);
return appObject;

}

设置为 AppObject 的 DimRequirement

@XmlRootElement
public class DimRequirement extends BaseObject implements Serializable {
private Long requirementKey;
private String description;
private String priority;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="requirementKey")
public Long getRequirementKey() {
return this.requirementKey;
}
public void setRequirementKey(Long requirementKey) {
this.requirementKey = requirementKey;
}
@Column(name="Description")
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
@Column(name="Priority")
public String getPriority() {
return this.priority;
}
public void setPriority(String priority) {
this.priority = priority;
}
}

堆栈跟踪

SEVERE: Mapped exception to response: 500 (Internal Server Error)
javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: class com.vxl.model.DimRequirement nor any of its super class is known to this context.
javax.xml.bind.JAXBException: class com.vxl.model.DimRequirement nor any of its super class is known to this context.]
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:159)
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)

我引用了以下链接 link 1 link 2但我无法解决问题。

最佳答案

为您的get方法,对应JAXBContext将建立在类 AppObject 上而不是 AppObject<DimRequirement> 类型.

@GET
@Produces({MediaType.APPLICATION_XML ,MediaType.APPLICATION_JSON})
@Path("/getreq")
public AppObject<DimRequirement> savePayment() {

您可以制作 JAXBContext将在 AppObject 上创建类意识 DimRequirement通过使用 @XmlSeeAlso注释。

@XmlRootElement
@XmlSeeAlso({DimRequirement.class})
public class AppObject<T> implements Serializable {

关于java - Jersey 休息服务显示异常 javax.ws.rs.WebApplicationException : javax. xml.bind.MarshalException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19113280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com