| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 |
Tags
- pessimistic lock
- optimistic lock
- generic type
- COPYOFRANGE
- propagation
- TDZ
- CQS
- cross-cutting concerns
- HandlerMethod
- 역정규화
- #@Transacional
- assertJ
- SPOF
- CORS
- NestJS 요청흐름
- RequestMappingHandlerMapping
- IllegalStateException
- 프로그래머스
- Generic method
- wrapper class
- ExceptionResolver
- Transaction
- tracking-modes
- demand paging
- 벌크연산
- API
- type eraser
- hoisting
- 단어변환
- Java
Archives
- Today
- Total
jingyulog
JSON Filtering 본문
방법 1. @JsonIgnore
필터를 적용하고자 하는 필드위에 적용시킬 수 있다.
@JsonIgnore
private String field2;
방법2. @JsonIgnoreProperties
필터를 적용하고자 하는 클래스위에 적용시킬 수 있다.
@JsonIgnoreProperties({"field1","field3"})
public class SomeBean {
private String field1;
@JsonIgnore
private String field2;
private String field3;
}
방법3. MappingJacksonValue
필터를 적용하고자 하는 컨트롤러 코드안에서 dynamic하게 적용시킬 수 있다.
@GetMapping(path = "/filtering")
public MappingJacksonValue getSomeBean() {
// MappingJacksonValue
SomeBean someBean = new SomeBean("value1", "value2", "value3");
MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(someBean);
SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.filterOutAllExcept("field1", "field3");
FilterProvider filters = new SimpleFilterProvider().addFilter("SomeBeanFilter", filter);
mappingJacksonValue.setFilters(filters);
return mappingJacksonValue;
}
@JsonFilter(value = "SomeBeanFilter")
public class SomeBean {
private String field1;
// @JsonIgnore
private String field2;
private String field3;
}'Tech > 스프링' 카테고리의 다른 글
| @Primary, @Qualifier 둘 중 무엇을 써야하나? (0) | 2023.08.02 |
|---|---|
| Resilience4j Circuit Breaker in Spring Boot3 (0) | 2023.07.18 |
| 406 Not Acceptable 해결 (0) | 2023.07.16 |
| 파일 업로드 (0) | 2023.07.01 |
| OAuth (0) | 2023.06.29 |