gpt4 book ai didi

java - 将字符串传递给使用 application/json 的 REST API

转载 作者:太空宇宙 更新时间:2023-11-04 07:37:23 25 4
gpt4 key购买 nike

我有一个看起来像这样的界面:

@Path("/myapi")
@Produces("application/json")
@Consumes("application/json")
public interface MyRestApi {

/// Some methods here that accept complex object and work fine

@GET
@Path("/methodwithstring")
public void methodWithString(final String thumbprint,
@Context final HttpServletResponse response);


}

当我将字符串传递给 methodWithString 方法时,我们得到一个类似于 "some-string" 的字符串。问题是引号,字符串到达​​用“包围的方法。我想了解如何在没有包围“的情况下传递它。

我猜发生这种情况是因为该类消耗了“application/json”。这是我们第一次将字符串作为参数传递,我们不知道如何解决这个问题。

最佳答案

尝试在类中移动@Consumes("application/json")

并制作 methodWithString @Consumes("text/plain")

我想这应该可行。

@Path("/myapi")
@Produces("application/json")
public interface MyRestApi {

/// Some methods here that accept complex object and work fine
// @Consumes("application/json")
// public void somemethods() ...

@GET
@Path("/methodwithstring")
@Consumes("text/plain")
public void methodWithString(final String thumbprint,
@Context final HttpServletResponse response);
}

关于java - 将字符串传递给使用 application/json 的 REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16644675/

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