泽西投掷"未找到MessageBodyWriter"每个GET请求都有例外吗?

时间:2014-06-26 22:37:26

标签: java json jackson jax-rs jersey-2.0

我有一个简单的实体,我试图使用Jersey 2.x和Jackson 2.x返回JSON编码。

但是,当我在浏览器中点击GET请求的端点时,它失败了:

HTTP Status 500 - org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class com.package.ResponseWrapper, genericType=class com.package.ResponseWrapper.

我怀疑这是由于某些缺乏依赖或版本不匹配。我尝试了几个,但我仍然遇到同样的问题。

我正在使用Maven,以下是与球衣相关的依赖关系的样子:

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.9.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.9.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-common</artifactId>
        <version>2.9.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-entity-filtering</artifactId>
        <version>2.9.1</version>
    </dependency>

    <dependency> 
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.4.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
        <version>2.4.1</version>
    </dependency>

我通过添加以下依赖项来阅读一些修复此问题的人:

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

...但是因为我在泽西岛2.x并使用杰克逊的提供商(jackson-jaxrs-json-provider),我不认为这是我的选择。< / p>

我不确定如何在这里继续..任何人对我可能遗失的内容有任何想法?

谢谢!

1 个答案:

答案 0 :(得分:0)

好的,发现了这个问题......

我忘了添加

packages("com.fasterxml.jackson.jaxrs.json");

到我的ResourceConfig班。

现在一切正常!