简体   繁体   English

显示异常javax.ws.rs.WebApplicationException的jersey休息服务:javax.xml.bind.MarshalException

[英]jersey rest services showing exception 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. 我正在使用jersey服务,我在这里提到,当我返回Java对象时,它工作正常。 Later i tried to make the java object generic its giving exception javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException 后来我尝试使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;
    }

}

my service 我的服务

@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;

    } 

DimRequirement which is setting to 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;
    }
}

stack trace 堆栈跟踪

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)

I referd following links link 1 link 2 but i was not able to solve the problem. 我引用了以下链接, 链接1, 链接2,但我无法解决问题。

For your get method, the corresponding JAXBContext will be built on the class AppObject and not the type AppObject<DimRequirement> . 对于您的get方法,将在类AppObject而不是类型AppObject<DimRequirement>上构建相应的JAXBContext

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

You can make the JAXBContext that will be created on the AppObject class aware of DimRequirement by using the @XmlSeeAlso annotation. 您可以在JAXBContext ,将在创建AppObject类意识到DimRequirement使用@XmlSeeAlso注解。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javax.ws.rs.WebApplicationException而不是Jersey Exception Mapper中的实际异常 - javax.ws.rs.WebApplicationException instead of the actual exception in Jersey Exception Mapper javax.ws.rs.WebApplicationException:javax.xml.bind.JAXBException,具有链接的异常类[Ljava.lang.Object; - javax.ws.rs.WebApplicationException: javax.xml.bind.JAXBException with linked exception class [Ljava.lang.Object; javax.xml.ws.WebServiceException:javax.xml.bind.MarshalException-带有链接的异常: - javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException - with linked exception: javax.ws.rs.WebApplicationException:com.sun.jersey.api.MessageException:Java REST Web服务中的JSON支持 - javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: JSON support in Java REST Webservices with Jersey Java web 客户端 CXF - JAXB 编组异常; 嵌套异常是 javax.xml.bind.MarshalException - Java web client CXF - JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException javax.xml.bind.MarshalException-带有链接的异常:[javax.xml.bind.JAXBException:class **或其任何超类对此上下文都是已知的 - javax.xml.bind.MarshalException - with linked exception: [javax.xml.bind.JAXBException: class ** nor any of its super class is known to this context NoClassDefFoundError:javax / ws / rs / WebApplicationException - NoClassDefFoundError: javax/ws/rs/WebApplicationException javax.ws.rs.WebApplicationException:HTTP 404服务器找不到请求的资源 - javax.ws.rs.WebApplicationException: HTTP 404 the server could not find the requested resource 此上下文已知javax.xml.bind.MarshalException或其任何超类 - javax.xml.bind.MarshalException nor any of its super class is known to this context Java REST 客户端 - javax.ws.rs.ProcessingException:javax/xml/bind/annotation/XmlTransient - Java REST Client - javax.ws.rs.ProcessingException: javax/xml/bind/annotation/XmlTransient
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM