java – spring boot not seeing request parameters

java – spring boot not seeing request parameters

Try this, Im not sure of your version of Spring Boot, you may have to tweak it a bit.

    // Somewhere in package /service/dto
class PayloadDTO {
 String payload;

 public setPayload(String payload) {
  this.payload = payload;

 public getPayload() {
  return payload;

// Resource method
public String login(@RequestBody PayloadDTO payload) throws IOException {
 log.error(Payload= + payload.getPayload());
 TypeReference < Map < String, String >> typeRef = new TypeReference < Map < String, String >> () {};
 Map < String, String > payloadMap = objectMapper.readValue(payload.getPayload(), typeRef);
 String username = payloadMap.get(NetworkKeyNames.KEY_USERNAME);
 String password = payloadMap.get(NetworkKeyNames.KEY_PASSWORD);

 String result = securityService.login(username, password);
 return result;

I ran a curl and the curl hit my web service, so Im back to my Angular app as to why its not sending the data as a post.

Thanks to Abhijit Sarkar for suggesting the curl. Id forgotten about that and it shed light on the problem.

java – spring boot not seeing request parameters

Looking at your code @RequestParam(NetworkKeyNames.KEY_PAYLOAD). Im guessing NetworkKeyNames.KEY_PAYLOAD has a string value. Spring will attempt to use that string value as the parameter name, so for example if NetworkKeyNames.KEY_PAYLOAD = pay; what you need to send to your controller is pay=testing.

Or you could just change:

@RequestParam(NetworkKeyNames.KEY_PAYLOAD) String payload


 @RequestParam String payload

this will use payload as the parameter name

Leave a Reply

Your email address will not be published. Required fields are marked *