feign
feign copied to clipboard
Expand POJO in URL params to multiple object params
Hi! I think I might need some help here.
Lets say, I have this API contract GET /api/v1/game
with url params - gameId, token, settings[language,currency]
In my case, I need the final URL to be like this: /api/v1/game?gameId=1&token=2&settings[language]=en&settings[currency]=USD
I have proper DTO with required fields including 'Settings' object. So for this scenario the temporary solution was using @Param("settings[language]")
and so on, but then I should get rid of Settings field.
Is there a more proper way to expand an POJO field to multiple URL params in the style I mentioned before?
You can create a custom Expander
. This will allow you to control the entire process related to query string parameter expansion.
You can model your function like this:
public Game getGame(@Param(expander=GameQuerySpecExpander.class) GameSpec spec);
Where GameSpec
is your DTO/Pojo that contains your value. The GameQuerySpecExpander
would be responsible for expanding the spec into your desired query string. See our documentation for more information.