Reputation: 85
Suppose I make a get request to foo() with the JSON body:
{
„a“: „hallo“,
„b“: „world“,
„aa“: 10
}
@PostMapping("/foo")
public void foo(@RequestBody MyClass myClass) {
//do stuff
}
class MyClass {
String a;
String b;
String c;
int aa;
}
If the JSON object and the class match, then it works fine and you get a MyClass object with the correct variables set. But now I want to set only those fields in the MyClass class that I have also passed and the rest is initialized with null. How can I do this?
Upvotes: 0
Views: 949
Reputation: 11
you have to change @GetMapping to @PostMapping if you want to use @RequestBody.
-Greetings :)
Upvotes: 0