feign icon indicating copy to clipboard operation
feign copied to clipboard

Expand POJO in URL params to multiple object params

Open desoliture opened this issue 1 year ago • 1 comments

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?

desoliture avatar Apr 21 '23 19:04 desoliture

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.

kdavisk6 avatar May 24 '23 14:05 kdavisk6