【问题标题】:Getting MessageBodyWriter not found for media type=application/json获取未找到媒体类型 = 应用程序/json 的 MessageBodyWriter
【发布时间】:2016-01-20 05:20:59
【问题描述】:

我已经尝试了所有方法...无法弄清楚为什么会出现此异常。有趣的是,在我的 IDE (Intellij) 中,一切都顺利进行。想不通……放弃。

你们有什么建议吗?

dependencies {
    compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.10.27'
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.7'
    compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2'
    compile group: 'ch.qos.logback', name: 'logback-core', version: '1.1.2'
    compile group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version: '2.22.1'
    compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version: '2.22.1'
    compile group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.22.1'
//    compile group: 'com.owlike', name: 'genson', version: '1.3'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'
    compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2+'
    compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.8.3'
    compile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.7'
    compile group: 'org.elasticsearch', name: 'elasticsearch', version: '1.5.2'

    testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
    testCompile 'cglib:cglib-nodep:2.2'       // For mocking classes
    testCompile 'org.objenesis:objenesis:1.2' // For mocking final classes
    testCompile group: 'junit', name: 'junit', version: '4.9'
}

获取以下信息:

2015 年 10 月 21 日上午 5:18:46 org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo SEVERE:找不到媒体的 MessageBodyWriter 类型=应用程序/json,类型=类 java.util.ArrayList, genericType=java.util.List.

【问题讨论】:

  • “在我的 IDE (Intellij) 中一切正常” - 所以你是说当你在你的 IDE 中运行服务器时它工作正常,但是当你运行它不是一个罐子吗?。
  • 在没有看到任何代码的情况下,我可以告诉您,这是您返回Response.ok(ArrayList<Something>()) 时的常见问题。这可以通过使用GenericEntity 解决,如here 所述
  • 我可能应该关闭这张票...我从 gradle 切换回 mvn,似乎将所有依赖项与 gradle 捆绑到一个 jar 中存在问题...仍然不确定是什么继续,但是当我运行 maven 创建的 fatjar 时它正在工作。很奇怪。它在 intellij 中有效,因为所有依赖项都在那里。

标签: java json intellij-idea jersey-2.0 grizzly


【解决方案1】:

我在 2.22.1 中遇到了同样的错误,我添加了以下依赖项并且它起作用了。

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>2.22.1</version>
    </dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-06
    • 2014-06-29
    • 2015-12-13
    • 2017-07-24
    • 2021-06-15
    • 2015-05-22
    相关资源
    最近更新 更多