java.lang.IllegalArgumentException: class com.gec.bean.Job declares multiple JSON fields named id
时间: 2024-05-24 11:13:20 浏览: 20
This error occurs when a class is annotated with @JsonAutoDetect and declares multiple fields with the same property name. For example, the class com.gec.bean.Job might look like this:
public class Job {
private int id;
private String name;
private int jobId;
// getters and setters
}
In this case, the id field is already being serialized by default because it follows the JavaBean naming convention for a property called "id". However, the jobId field is also being serialized with the property name "id", which causes a conflict.
To resolve this issue, you can either change the property name of one of the fields or use annotations such as @JsonProperty to specify a different name for one of the fields. For example:
public class Job {
private int id;
private String name;
@JsonProperty("jobId")
private int jobId;
// getters and setters
}
With this change, the jobId field will be serialized with the property name "jobId" instead of "id", avoiding the conflict.
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)