Spring Boot3 & Spring Framework 6 강의 ::Section.8 REST API 동적,정적 필터링 구현하기

suragryen·2024년 3월 14일
0

Udemy-Spring

목록 보기
23/25

serialization: 객체를 직렬화 함 (Json 또는 xml로 전환하는 것 )

  1. Customize field names in response

@JsonProperty

  • Json key값 커스텀마이징 가능
  1. Return only selected fileds
  • 빈에 정의된 비밀번호가 있는데 응답에는 비밀번호를 전송하고 싶지 않다면
  1. 정적필터링 : REST API 와 관계없이 특정 필드를 차단하거나 필터링

  • @JsonIgnore


  • @JsonIgnoreProperties : 클래스 단위로 필터링
  1. 동적 필터링 : 응답의 일부로 필드를 전송할지 동적으로 결정
	@GetMapping("/filtering")
	public MappingJacksonValue filtering() {
		//MappingJacksonValue : REST API 메서드에 데이터뿐 아니라 필터링 방식도 정의
		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;
		
	}
profile
블로그 이사중 ☃︎

0개의 댓글

관련 채용 정보