How do i ignore a specific field from an list in JSON response

Viewed 487

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

Sample 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 ?

1 Answers

Jackson has a solution for that. Simply use @JsonIgnore You can see it in the example below

@JsonIgnore
public String getPassword() {
    return password;
}

Now the password information won’t be serialized to JSON.

Also you can try with @JsonIgnoreProperties

Related