我使用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使用Maven与JAXB的JSON
所以我只是想发送一个简单的bean作为JSON对象。我已经遵循了所有的步骤,但我无法发送JSON对象(尽管我正确接收了XML格式)。我获得以下异常:com.sun.jersey.api.MessageException:Java类de.vogella.jersey.jaxb.model.Todo的消息正文编写器,以及Java类类de.vogella.jersey.jaxb.model。 Todo和MIME媒体类型应用程序/ 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>
非常感谢您
正在非Oracle JDK上运行?没想过。 Oracle JDK捆绑了JAXB RI,因此您不需要eclipse链接(替代JAXB impl。)依赖关系。 –