JSON与使用Maven的JAXB

JSON与使用Maven的JAXB,json,jaxb,jersey,jax-rs,Json,Jaxb,Jersey,Jax Rs,我正在使用Jersey(与Jetty一起)和Maven实现RESTful服务。我正在尝试使用JAXB发送JSONObject,我已经学习了一些教程,如:和 所以我有一个简单的bean,我想作为JSON对象发送它。我已经完成了所有步骤,但是我无法发送JSON对象(尽管我确实正确地接收了XML格式)。我获得以下异常:com.sun.jersey.api.MessageException:Java类de.vogela.jersey.jaxb.model.Todo的消息体编写器,Java类型类de.vo

我正在使用Jersey(与Jetty一起)和Maven实现RESTful服务。我正在尝试使用JAXB发送JSONObject,我已经学习了一些教程,如:和

所以我有一个简单的bean,我想作为JSON对象发送它。我已经完成了所有步骤,但是我无法发送JSON对象(尽管我确实正确地接收了XML格式)。我获得以下异常:com.sun.jersey.api.MessageException:Java类de.vogela.jersey.jaxb.model.Todo的消息体编写器,Java类型类de.vogela.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>

朱尼特
朱尼特
3.8.1
测试
泽西岛
泽西服务器
1.11
泽西岛
泽西servlet
1.11
泽西岛
泽西json
1.11
org.mortbay.jetty
码头
6.1.26

非常感谢

我找到了缺少的依赖项:

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.0.0</version>
        <scope>compile</scope>
    </dependency>

org.eclipse.persistence
日食
2.0.0
编译
我还必须添加一个存储库,以避免丢失原型错误:

<repositories>
    <repository>
        <id>EclipseLink Repo</id>
        <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo</url>
    </repository>
</repositories>

日食回购
http://www.eclipse.org/downloads/download.php?r=1&nf=1&;文件=/rt/eclipselink/maven.repo

我找到了缺少的依赖项:

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>2.0.0</version>
        <scope>compile</scope>
    </dependency>

org.eclipse.persistence
日食
2.0.0
编译
我还必须添加一个存储库,以避免丢失原型错误:

<repositories>
    <repository>
        <id>EclipseLink Repo</id>
        <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo</url>
    </repository>
</repositories>

日食回购
http://www.eclipse.org/downloads/download.php?r=1&nf=1&;文件=/rt/eclipselink/maven.repo

是否在非Oracle JDK上运行?我没想过。Oracle JDK将JAXB RI打包成现成的,因此您不需要eclipse链接(替代JAXB impl.)依赖项?我没想过。Oracle JDK将JAXB RI打包成现成的,因此您不需要eclipse链接(替代JAXB impl.)依赖项。