在resteasy应用程序中手动添加jaxb的提供程序

时间:2016-06-21 04:18:00

标签: rest jaxb jax-rs resteasy undertow

我有一个休息应用程序,我使用resteasy和jaxb来生成json输出

@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("/data")
public MyResponse getData {
    return new MyResponse("my response"); // Just stubbing this
}

@XmlRootElement(name = "response")
@JsonInclude(Include.NON_NULL)
public class MyResponse {
    private String data;

    public MyResponse(String data) {
        this.data = data;
    }
    public String getData() {
        return data;
    }
    public void setData(String data) {
        this.data = data;
    }
}

我没有使用web.xml,而是创建了一个RestApplication,它扩展了Application并覆盖了getSingletons和getClasses方法。

现在我不确定我需要添加哪些jaxb提供程序类来实现上述工作,我的意思是执行json序列化。

我收到以下错误

Could not find MessageBodyWriter for response object of type:MyResponse of media type: application/json

你能让我知道我需要手动添加哪些类(提供者)才能使其工作吗?

0 个答案:

没有答案