I have set the callback URL to one of my controller methods in spring boot application. But I'm unable to understand how to parse the events being sent to this method. I figured there are two ways to do this.
Note: End goal is to map each event type (task, worker, etc) to their respective POJOs that I've created in the application.
- Using request.getParameterMap(). I reckon this would require to iterate over each key and use my POJO's setters to set the values.
@PostMapping(value="event/twilio")
public void eventCallback(HttpServletRequest request) {
Logger.info("Event payload: " + request.getParameterMap());
}
- Accepting String body in the method itself. The
eventPayload
appears to be an Urlencoded value rather than a json string.
@PostMapping(value="event/twilio")
public void eventCallback(@RequestBody String eventPayload) {
Logger.info("Event payload: " + eventPayload);
}