@RestController
@RequestMapping("/api")
@Slf4j
public class PutApiController {
@PutMapping("/put")
public void put(
@RequestBody UserRequest userRequest
){
log.info("Request: {}", userRequest);
}
}
http://localhost:8080/api/put
//body:
{
"user_name": "Choi Seunghwan",
"user_age": 15,
"email": "choi12345@gmail.com",
"is_Korean": true
}
we get
2024-10-28T21:00:46.617+09:00 INFO 9404 --- [rest-api] [nio-8080-exec-8] c.e.r.controller.PutApiController : Request: UserRequest(userName=Choi Seunghwan, userAge=15, email=choi12345@gmail.com, isKorean=false)
Above, isKorean in the log is "false" although in the body of the request it was stated as true. isKorean in "UserRequest" is a boolean type. The automatically generated set method for "isKorean" field by Lombok is setKorean(), not setIsKorean(), hence the mismatch.

We can solve this with 2 methods:
1. Modifying the key field in json body:
{
"user_name": "Choi Seunghwan",
"user_age": 15,
"email": "choi12345@gmail.com",
"Korean": true
}
UserRequest(userName=Choi Seunghwan, userAge=15, email=choi12345@gmail.com, isKorean=true)@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class UserRequest {
private String userName;
private Integer userAge;
private String email;
private Boolean isKorean; //default is false
}
//json
{
"user_name": "Choi Seunghwan",
"user_age": 15,
"email": "choi12345@gmail.com",
"is_korean": true
}
//output
UserRequest(userName=Choi Seunghwan, userAge=15, email=choi12345@gmail.com, isKorean=true)