【发布时间】:2017-06-06 16:56:24
【问题描述】:
public interface ItemsClient {
@RequestLine("POST /items")
public Map<String, Object> post(Map<String, Object> item);
}
然后
ItemsClient itemsClient = Feign.builder().decoder(new GsonDecoder()).encoder(new GsonEncoder()).target(ItemsClient.class, ROOT_URI);
Map<String, Object> myNewItemWithId = itemsClient.post(myNewItem);
服务器发送带有如下正文的响应:
{
"id" : 108171343002018,
"name" : "myNewItem among many and many !"
}
然后是 myNewItemWithId.get("id"); 的值是2147483647,Integer的最大值。
有没有办法告诉 GsonDecoder 将整数解码为 Long ?
【问题讨论】:
-
我不了解 gsondecoder,但您始终可以将 id 发送为两个整数而不是 long
-
这似乎是how gson works。如果您想将数字解码为 long,您需要自己的结构化类型,这对于具有“许多和许多”属性的对象可能并不容易。所以,是的,最好使用另一个库,如您发现的 Jackson。