My app use spring boot with lombok, when I use @Data
annation will cause
java.lang.IllegalArgumentException: No converter found for return value of type.
When I expicity write getter and setter, it works good.
Please help me, thanks; The code:
@RestController
@RequestMapping("/user")
public class UserController {
@GetMapping("/{id}")
public User query(@PathVariable long id) {
if (id == 1L) {
return new User(1l);
} else {
return new User(2L);
}
}
}
@Data
public class User {
private long userId;
private String userName;
private String password;
private String mobile;
private String address;
public User() {
}
public User(long userId){
this(userId, "zhengfc", "pwd", "13322222222", "shanghai-zhengjiang");
}
public User(long userId, String userName, String password, String mobile, String address) {
this.userId = userId;
this.userName = userName;
this.password = password;
this.mobile = mobile;
this.address = address;
}
}