의존성 추가
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.1'
JsonIgnore()
- JsonIgnore을 필드 위에 붙여주면 데이터를 주고 받을 때 해당 데이터는 Ignore된다
public class User{
private Long id;
@JsonIgnore()
private String name;
}
{
id:1
}
@JsonIgnoreProperties(value)
@Data
@AllArgsConstructor
@JsonIgnoreProperties(value={"password","id"})
public class User {
@JsonFilter(value)
@JsonFilter("UserInfo")
public class User {
List<User> users = service.findAll();
SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter
.filterOutAllExcept("id", "name", "joinDate", "password");
FilterProvider filters = new SimpleFilterProvider().addFilter("UserInfo", filter);
MappingJacksonValue mapping = new MappingJacksonValue(users);
mapping.setFilters(filters);
return mapping;