Setting up an Java Postman call assigning values to the variables but its shows null.
@PostMapping("/caStudents/student")
public String generateSignedValue(@RequestBody StudentRequest studentRequest) throws Exception
String signedValue=studentService.getSignedValue(studentRequest);
return signedValue;
My Pojo Student
Class
public class StudentRequest {
String user;
Long duration ;
public String getPublicKey() {
return publicKey;
}
public void setPublicKey(String publicKey) {
this.publicKey = publicKey;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public Long getDuration() {
return duration;
}
public void setDuration(Long duration) {
this.duration = duration;
}
Postman Request
{"studentRequest":[{"user":"admin","duration":19336}]}
CodePudding user response:
your request body should be like this:
{"user":"admin","duration":19336}
because you are getting StudentRequest
as RequestBody
and it means you should send StudentRequest
internal properties not containing StudentRequest
it self in request ,
second problem is that your RequestBody
contains singular object not array .
CodePudding user response:
request body should be {"user":"admin","duration":19336}
CodePudding user response:
According to what you've given us your request should actually be
{
"user": "admin",
"duration": 19336
}
If you want to provide multiple student requests at once (within an array), then you're StudenRequest
class should look somewhat like this:
public class StudentRequest {
List<StudentR>;
// Getter and Setter or not in case you use lombok
class StudenR {
String user;
Long duration ;
}
}