简体   繁体   中英

NoMessageBodyWriterFoundFailure when trying to access pojo

I'm trying to migrate a webservice project to resteasy from jersey, and I'm getting a strange error:

ERROR [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-42) RESTEASY002005: Failed executing GET /directors/tmlist/dirUsr: org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: com.company.sales.beans.Resource of media type: application/json

Everything I've been able to find online has told me that I need to add an annotation to the pojo causing the problem, but it doesnt seem to have made any kind of difference.

The pojo I'm working with is:

package com.company.sales.beans;

import javax.xml.bind.annotation.*;
import java.util.List;

@XmlRootElement
public class Resource<T> {
    @XmlAnyElement(lax = true)
    @XmlElement(name = "content")
    private List<T> m_Content;
    @XmlAttribute(name = "type")
    private String m_Type;
    @XmlAttribute(name = "src")
    private String m_Source;
    @XmlElementRef(name = "links")
    private List<Link> m_Links;

    /**
     *
     */
    public Resource() {
        m_Content = null;
        m_Type = null;
        m_Source = null;
    }

    /**
     * @return the m_Content
     */
    public List<T> getContent() {
        return m_Content;
    }

    /**
     * @param m_Content the m_Content to set
     */
    public void setContent(List<T> m_Content) {
        this.m_Content = m_Content;
    }

    /**
     * @return the m_Type
     */
    public String getType() {
        return m_Type;
    }

    /**
     * @param m_Type the m_Type to set
     */
    public void setType(String m_Type) {
        this.m_Type = m_Type;
    }

    /**
     * @return the m_Source
     */
    public String getSource() {
        return m_Source;
    }

    /**
     * @param m_Source the m_Source to set
     */
    public void setSource(String m_Source) {
        this.m_Source = m_Source;
    }

    /**
     * @return the m_Links
     */
    public List<Link> getLinks() {
        return m_Links;
    }

    /**
     * @param m_Links the m_Links to set
     */
    public void setLinks(List<Link> m_Links) {
        this.m_Links = m_Links;
    }


}

This was created by a previous employee at the company I work for and as far as I can tell was working fine with the previous library they were using (jersey 1.17). I'm not entirely sure why resteasy is still complaining about the missing message body writer, as I've found a few different sites claiming adding the @XmlRootElement should make it default to some built in writer/reader.

Did you see this link ?

It says to add @XmlElement(required = true) .

Another thing is this looks like a generic type. Could it be RESTEasy doesn't like or can't handle objects that use generics?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM