I've made a rest client, using the feign framework, as follows:
@Headers({"Content-Type: application/x-www-form-urlencoded"})
public interface CampaignTrigger {
@RequestLine("POST /event?actid={actid}&key={key}&event={event}&visit={visit}")
TriggerResponse trigger(@Param("visit") Map<String, String> visit, @Param("actid") String actid, @Param("key") String key, @Param("event") String event);
}
This results in something like this:
http://www.example.com/event?actid=1234&key=1234&event=cool_event&visit={email=someone@hosting.com}
What I want is for the 'visit' parameter to be a json, like this:
http://www.example.com/event?actid=1234&key=1234&event=cool_event&visit={"email":"someone@hosting.com"}
Who knows how to accomplish this?
You can define your own Param.Expander
to achieve it like below.
@Headers({"Content-Type: application/x-www-form-urlencoded"})
public interface CampaignTrigger {
@RequestLine("POST /event?actid={actid}&key={key}&event={event}&visit={visit}")
TriggerResponse trigger(@Param(value="visit", expander = JSONExpander.class) Map<String, String> visit, @Param("actid") String actid, @Param("key") String key, @Param("event") String event);
}
static final class JSONExpander implements Param.Expander {
@Override
public String expand(Object value) {
// convert value to json string and return it.
return xxxx;
}
}