找不到内容类型应用程序/XML类型的编写器 [英] Could not find writer for content-type application/xml type

查看:77
本文介绍了找不到内容类型应用程序/XML类型的编写器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此解决方案来尝试消除我的问题,但是却失败了:

I am following this solution to try and eliminate my issue, but am failing miserably: RESTEasy: Could not find writer for content-type application/json type

这是我的Maven依赖项:

Here are my maven dependencies:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>2.2.1.GA</version>
</dependency>
<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.9</version>
</dependency>
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2.12</version>
</dependency>

这是我创建的XML类,可以进行编组/拆组.

Here is a XML class that I created that I marshall/unmarshall.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Cools")
public class CoolXml {

    @XmlAttribute
    private Boolean isCool;

    public Boolean getIsCool() {
        return isCool;
    }

    public void setIsCool(final Boolean isCool) {
        this.isCool = isCool;
    }
}

使用此代码调用端点时,最后一行会生成错误:

When calling the endpoint with this code, the last line generates the error:

final String url = "http://localhost:8080/sample/getcools";
final ClientRequest request = new ClientRequest(url);
request.header(HttpHeaderNames.ACCEPT, MediaType.APPLICATION_XML);
final CoolXml req = new CoolXml(project);
request.body("application/xml", req);
final ClientResponse<CoolXmlResponse> response = request.post(CoolXmlResponse.class);

我收到超级烦人的错误:

I get the super annoying error:

 java.lang.RuntimeException: could not find writer for content-type application/xml type: cool.CoolXml

我需要任何其他依赖吗?

Do I need any additional dependencies?

推荐答案

我最终使用了这种依赖关系:

I ended up using this dependency:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-client</artifactId>
    <version>1.8</version>
</dependency>

然后,我最终使用以下类来测试请求:

Then, I ended up using the following classes to test a request:

final Client client = Client.create();
final WebResource webResource = client.resource(url);
final CoolXml requestXml = new CoolXml();
... some data setting
final ClientResponse response = webResource.accept("application/xml").post(ClientResponse.class, requestXml);

这篇关于找不到内容类型应用程序/XML类型的编写器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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