gpt4 book ai didi

netflix-feign - Feign rest client,禁用对特定接口(interface)方法的解码

转载 作者:行者123 更新时间:2023-12-04 03:09:53 26 4
gpt4 key购买 nike

通过学习曲线,遇到了这个场景:

鉴于90%的调用都是JSON,在构建客户端时添加了GSON解码器。不过接口(interface)中有些方法调用应该是支持raw return without decoded的。

@RequestLine("GET /rest/myrawmethod")
String getRawMethod();

目前,由于 GSON 被添加为解码器,它不会返回原始字符串,而是尝试对其进行解码(它看起来确实像 JSON 内容,但我想绕过解码)。当不使用 GSON 解码器作为异常(exception)时,我似乎找不到一种简单的方法来禁用特定的接口(interface)方法。

谢谢!

最佳答案

看到一些对各种方法的引用,这似乎是目前最好的途径:

@RequestLine("GET /rest/myrawmethod")
feign.Response getRawMethod();

然后当你去解析响应时,使用类似的东西:

feign.codec.Decoder dc = new Decoder.Default();
String strresponse = dc.decode(myfeignresponse, String.class); //wrapped with exception handling

在 REST 有效负载周围没有任何东西,只有方法调用的情况下,这是制作原型(prototype)的好方法……或者想要做一些更奇特的事情(比如使用 feign.Response 流方法)。

关于netflix-feign - Feign rest client,禁用对特定接口(interface)方法的解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46077995/

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