泽西休息服务显示异常javax.ws.rs.WebApplicationException:javax.xml.bind.MarshalException [英] jersey rest services showing exception javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException

查看:203
本文介绍了泽西休息服务显示异常javax.ws.rs.WebApplicationException:javax.xml.bind.MarshalException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on jersey services which i mentioned here it is working fine when i am returning a java object. Later i tried to make the java object generic its giving exception 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
但是我不是 能够解决问题。

I referd following links link 1 link 2 but i was not able to solve the problem.

推荐答案

对于 get 方法,相应的 JAXBContext 将构建在类 AppObject 上,而不是类型 AppObject< DimRequirement>

For your get method, the corresponding JAXBContext will be built on the class AppObject and not the type AppObject<DimRequirement>.

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

你可以制作 JAXBContext 将通过使用 @XmlSeeAlso <在 AppObject 类中创建,知道 DimRequirement / code>注释。

You can make the JAXBContext that will be created on the AppObject class aware of DimRequirement by using the @XmlSeeAlso annotation.

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

这篇关于泽西休息服务显示异常javax.ws.rs.WebApplicationException:javax.xml.bind.MarshalException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆