0

I have recently started learning spring boot and when I am trying to pass id or age in postman to test it I am getting value as 1 for id and 25 for age (I have declared id and age as Integers in method parameter).

Here is a code from controller

@RestController
@RequestMapping("/student/")

public class StudentController {

@GetMapping()
public Integer getStudents(  @RequestParam()  Integer id,@RequestParam()  Integer age ){

    
    return age;
    
}

Here is the screenshot from postman

enter image description here

When I declare id and age as Strings in method params The results are 1,value for id and 25,value for age .

For all the other queryparams the reults are as expected .

What is the reason for this? How does spring convert types?

Any help is appreciated . Thank you .

Ramu
  • 147
  • 1
  • 13

1 Answers1

0

As per this community issue https://github.com/spring-projects/spring-framework/issues/10584

I see a comment stating Annotation properties can only be of type String, Enumeration, Class, Annotation, primitives, or arrays of these types.

Can you please try with int ?

Check this article too, if this is relating to your issue How to give default value as integer in @RequestParam()

Harsh
  • 812
  • 1
  • 10
  • 23
  • Seems like the issue is happening only with the parameters as id or age because with other parameter names the result is as expected . I have tried to change the id type to String , Integer,int but the result is same . it returns 1 for id when return type is Integer and "1 , valuePassed " when the return type is String . – Ramu Jun 19 '22 at 04:03