[英]How do i ignore a specific field from an list in JSON response
I am trying to ignore a specified field from a list during deserialization.我试图在反序列化期间忽略列表中的指定字段。 I am not sure how do i do that for a field that sits inside a list.
我不确定如何为位于列表中的字段执行此操作。 Below is my json and response class
下面是我的 json 和响应类
Sample json示例 json
{
"key": {
"rowKey": "123"
},
"names": [
{
"firstName": "JON ",
"firstNameFormatted": "JON"
}
]
}
Response class响应类
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
public class Data {
private Map<String,Object> key;
private List<Map<String,Object>> names;
}
Here i would like to ignore在这里我想忽略
firstNameFormatted
名字格式
from my json response but i am not sure how to do that using jackson for a field that is inside a list ?来自我的 json 响应,但我不确定如何使用 jackson 来处理列表中的字段?
Jackson has a solution for that.杰克逊有一个解决方案。 Simply use
@JsonIgnore
You can see it in the example below只需使用
@JsonIgnore
就可以在下面的示例中看到它
@JsonIgnore
public String getPassword() {
return password;
}
Now the password information won't be serialized to JSON.现在密码信息不会被序列化为 JSON。
Also you can try with @JsonIgnoreProperties
您也可以尝试使用
@JsonIgnoreProperties
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.