'Feign QueryMap usage with POJO
I've found in FEIGN-README that I can do stuff like:
interface MarketDataRestClient {
@RequestLine("GET /api/v1/depth")
fun getOrderBook(@QueryMap orderBookQuery: OrderBookQuery) : OrderBook
}
OrderBookQuery:
data class OrderBookQuery(val symbol: String, val limit: Int? = 100)
And Feign should generate query params: /api/v1/depth?symbol={symbol}&limit={limit}
Unfortunately all I'm getting is:
Exception in thread "main" java.lang.IllegalStateException: QueryMap parameter must be a Map: class OrderBookQuery
at feign.Util.checkState(Util.java:128)
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:126)
at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:64)
at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:146)
at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:53)
at feign.Feign$Builder.target(Feign.java:198)
at feign.Feign$Builder.target(Feign.java:194)
Solution 1:[1]
This feature will be available in 9.7
. The current published version, as of the writing of this answer, is 9.6
. If you do not want to wait, please clone the repository and run build the project.
Solution 2:[2]
Just add a QueryMapEncoder,like?
return Feign
.builder()
.client(new OkHttpClient())
.logger(new Logger.ErrorLogger()).logLevel(Logger.Level.BASIC)
.queryMapEncoder(new BeanQueryMapEncoder())
.encoder(new GsonEncoder())
.decoder(new GsonDecoder())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Kevin Davis |
Solution 2 | ?????? |