Search code examples
javaspringspring-bootrequest-mapping

Spring Boot @RequestBody does not copy parameters fully


I have a JSON object that I pass to an API endpoint:

{
    "ID": 12312,
    "location": "London",
    "friends": 1231,
    "Name": "dsd",
    "verified": true

}

I have an endpoint UserController:

@PostMapping("saveUser")
public String Save(@RequestBody(required = true) User newUser){
    //TODO: User needs to have ID and all other necessary params
    //TODO: RequestBody is not working. Why not?

    userservice.saveNewUser(newUser);
    return "True";
}

and I have a User class:

@NodeEntity
public class User {

    @Id
    private long ID;
    private String Name;
    private String location;
    private int friends;
    private boolean verified;
    private int followers; 
    .... getters and setters

My problem: when I insert a user, the database registers the correct friends and location filed, but the ID and followers field and name are incorrect. Does anyone know why?wrong parameters parsed


Solution

  • camelCase. Try changing ID to id and Name to name. Frameworks assumes getID would have been declared as iD.