找不到 MessageBodyWriter 类型的响应对象:java.util.LinkedHashMap 媒体类型:application/json

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12142712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 07:46:28  来源:igfitidea点击:

Could not find MessageBodyWriter for response object of type: java.util.LinkedHashMap of media type: application/json

javajsontomcatjbossresteasy

提问by tun_eng

I have this REST service that returns JSON code :

我有这个返回 JSON 代码的 REST 服务:

@GET
@Path("/mypath")
@Produces(MediaType.APPLICATION_JSON)
public Response getS() {
    Map<String, String> map = new LinkedHashMap<String, String>();

    map.put(key1, val1);
    map.put(key2, val2);

    return Response.ok(map, MediaType.APPLICATION_JSON).build();
}

This service is deployed in a Tomcat server. I am using RESTeasy as framework. When trying to access the service, I encounter this:

该服务部署在 Tomcat 服务器中。我使用 RESTeasy 作为框架。尝试访问该服务时,我遇到了以下问题:

Could not find MessageBodyWriter for response object of type: java.util.LinkedHashMap of media type: application/json.

找不到 MessageBodyWriter 类型的响应对象:java.util.LinkedHashMap 媒体类型:application/json。

I didn't understand what is the problem.

我不明白有什么问题。

Thanks in advance

提前致谢

回答by yntelectual

How do you deploy your application? What application server do you use? What version of RestEasy? What RestEasy configuration have you specified(in web.xml or Application class)? Resteasy relies on providers for serialization/deserialization of objects. These providers need to contained in the classpath of your JAX-RS application. Depending on your build, application packaging and runtime environment these providers might be missing. Furthermore, discovery of providres can be configured, e.g. automatically discover all privoders in classpath, or only use those explicitly mentioned in conf. Commonly used providers with application/json capabilities are resteasy-Hymanson-provider, resteasy-jettison-provider. Verify that at least one of these is available in your classpath.

你如何部署你的应用程序?你使用什么应用服务器?什么版本的 RestEasy?您指定了什么 RestEasy 配置(在 web.xml 或 Application 类中)?Resteasy 依赖提供程序来进行对象的序列化/反序列化。这些提供程序需要包含在 JAX-RS 应用程序的类路径中。根据您的构建、应用程序打包和运行时环境,这些提供程序可能会丢失。此外,可以配置providres 的发现,例如自动发现classpath 中的所有privoders,或者只使用conf 中明确提到的那些。具有 application/json 功能的常用提供程序是resteasy-Hymanson-providerresteasy-jettison-provider。验证您的类路径中至少有一个可用。