【发布时间】:2012-06-18 15:38:35
【问题描述】:
我正在使用 Jersey(带有 Jetty)和 Maven 来实现 RESTful 服务。我正在尝试使用 JAXB 发送 JSONObject,我遵循了一些教程,例如:http://jersey.java.net/nonav/documentation/1.7/user-guide.html#d4e919 和 http://www.vogella.com/articles/REST/article.html
所以我只有一个简单的 bean,我想将它作为 JSON 对象发送。我已按照所有步骤操作,但无法发送 JSON 对象(尽管我确实正确接收了 XML 格式)。我得到以下异常:com.sun.jersey.api.MessageException:Java 类 de.vogella.jersey.jaxb.model.Todo 和 Java 类型类 de.vogella.jersey.jaxb 的消息正文编写器。 model.Todo,未找到 MIME 媒体类型 application/json
我尝试了各种不同的解决方案,但似乎没有任何效果。 我想知道我是否必须缺少任何依赖项,或者我必须实现一个 ContextResolver(尽管任何教程都将它们用于像这些简单的对象)。
这些是我拥有的依赖项:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Jersey -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.11</version>
</dependency>
<!-- Json -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.11</version>
</dependency>
<!-- Jetty -->
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.26</version>
</dependency>
</dependencies>
非常感谢
【问题讨论】: