gpt4 book ai didi

java - 强制从 Jersey 响应中获取 json

转载 作者:行者123 更新时间:2023-12-01 14:57:59 28 4
gpt4 key购买 nike

我正在尝试实现这个example 。 FileResource 中的第一个方法应该返回 json 响应,但响应是以 XML 形式传递的。我以前从未使用过 Jersey 。我尝试添加 @products 产生以下结果:

@GET @Produces("application/json")
@Path("/url")
public Response getCallbackUrl() {
String url = blobstoreService.createUploadUrl("/rest/file");
return Response.ok(new FileUrl(url)).build();
}

现在我明白了

A message body writer for Java class FileUrl, and Java type class FileUrl, and MIME media type application/json was not found

我该如何解决这个问题?谢谢你的帮助。如果您需要更多信息,请告诉我。我不太了解 Jersey 术语。

最佳答案

您需要更多依赖项才能生成 JSON 输出。

看看:http://jersey.java.net/nonav/documentation/latest/chapter_deps.html

向下滚动至:

11.4.1.2. MOXy Maven developers, using JSON serialization support of JAXB beans when using the MIME media type application/json require a dependency on the jersey-json module (explicit dependency on org.eclipse.persistence.moxy is required).

<小时/>

您可能感兴趣的“ Vanilla ” Jersey 的替代品是 Dropwizard 。他们的简介是:

Dropwizard has out-of-the-box support for sophisticated configuration, application metrics, logging, operational tools, and much more, allowing you and your team to ship a production-quality HTTP+JSON web service in the shortest time possible.

关于java - 强制从 Jersey 响应中获取 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14096383/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com