为什么编写媒体类型应用程序/ json失踪 [英] Why writer for media type application/json missing

查看:88
本文介绍了为什么编写媒体类型应用程序/ json失踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有一个宁静的服务(post)消耗( application / json )并生成( application / json )。此服务的单个参数是带注释的java对象。

Basically I have a restful service (post) that consumes(application/json) and produces (application/json). The single param for this service is an annotated java object.

我正在使用 org.jboss.resteasy.client.ClientRequest 将请求发送给服务。但是,我在客户端和异常中收到此异常:

I am using org.jboss.resteasy.client.ClientRequest to send the request to the service. However, I am getting this exception in the client end and the exception:


找不到内容类型 application / json 类型。

这是否意味着我缺少一些库jar或我必须为application / json编写自己的编写器?

Does this mean that I am missing some library jars or I have to write my own writer for application/json?

我正在使用resteasy 1.1

I am using resteasy 1.1

标记

推荐答案

拉曼是对的。 Jettison是一个有效的选择。你也可以使用杰克逊。
如果您使用maven,就像在pom中包含以下依赖项一样简单:

Raman is correct. Jettison is a valid option. You can also use Jackson. If you are using maven, it is as simple as including the following dependency in you pom:

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
        <version>2.3.2.Final</version>
    </dependency>

此时编写代码应该没有问题,例如:

At which point you should have no problem writing code such as:

    SomeBean query = new SomeBean("args")
    request.body("application/json", query);
    ClientResponse response = request.post();

这篇关于为什么编写媒体类型应用程序/ json失踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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