@JsonIgnore 어노테이션 적용이 안됩니다..
606
작성한 질문수 2
질문처럼 강의에서나온 @JsonIgnore 어노테이션 적용이 되지않고 PostMan 에서 그대로 필드가 노출되는 현상입니다.
왜 적용이 안되는지 알수 있을까요 서버도 재기동 한 상태입니다.
답변 1
0
안녕하세요, 이도원입니다.
https://www.inflearn.com/questions/685212
위 질문에 올려주셨던 코드로 설명을 드립니다.
@JsonIgnore로 필드를 제어할 실때는 Controller에서 MappingJacksonValue로 반환하지 않고 원래의 User 객체로 반환하시면 됩니다. 아래 코드 참고해서 실행해 보시기 바랍니다. 올려주신 코드의 User클래스를 TestUser 클래스로 변경하여 사용하였습니다.
@Data //lombok 사용으로 생성자,setter,getter 자동으로 생성됨
@AllArgsConstructor
//@JsonIgnoreProperties(value={"password","ssn"}) //숨길 데이터를 제어하기 위한 어노테이션
//@JsonFilter("UserInfoV1") //Userinfo 라는 정보는 controler , service 에서 사용 가능하게됨
@NoArgsConstructor //디폴트생성자 생성
public class TestUser {
private Integer id;
@Size(min =2, message = "Name은 2글자 이상 입력해 주세요.")
private String name;
@Past
private Date joinDate;
@JsonIgnore
private String password;
@JsonIgnore
private String ssn;
}@GetMapping(value ="/users/{id}",produces = "application/vnd.company.appv3+json")//mimetime을 이용하는 방법
public TestUser retrieveUserV3(@PathVariable int id){ //int로 자동으로 변환됨
User user = service.findOne(id);
if (user == null){
throw new UserNotFoundException(String.format("ID[%s] not found",id));
}
TestUser testUser = new TestUser();
BeanUtils.copyProperties(user, testUser);
return testUser;
}

감사합니다.
JPA
0
57
1
jpa dependency를 추가하고 SecurityConfig클래스에서 오류가 납니다.
0
68
1
웹 브라우저 400 bad request
0
71
1
@Size는 되는데 @Past는 안 됩니다.
0
61
1
pdf 자료는 없나요?
0
73
2
locale 정보가 null 이면 무조건 messages_ko.properties이 호출 되는 문제
0
87
2
Swagger 강의, Unable to infer base url 이거 뜨시는 분들 도움되시라고
0
118
1
강의에서나온 화면 피피티
0
158
1
HelloWorldBean 관련 에러
0
183
2
Swagger API 3.x 오류..
0
219
1
java: variable message not initialized in the default constructor 에러는 어찌하면 좋을까요?
1
282
1
현재 GIT에 올리신 소스를 실행해봤습니다.
0
189
2
고양이 소리가 귀엽네요 !!
0
137
2
git에서 소스받고 실습중인데
0
117
1
post가 안되요
0
102
1
한국어 같은 경우 언어코드인 messages_ko.properties 로 생성하는게 더 좋지 않나요?
0
167
2
리턴타입으로서 EntityModel<User> 와 ResponseEntity질문
0
103
1
예외처리쪽 관련 질문있습니다.
0
159
2
엔티티가 바로 응답으로 나가도 되나요??
0
221
2
안녕하세여 Cannot invoke "co.kr.joneconsulting.resfulservice.repository.PostRepository.save(Object)" because "this.postRepository" is null
0
135
2
사용자 등록하고 나서 H2 에서 보면 신규 사용자의 password, ssn 이 null 로 되어 있습니다.
0
140
2
ApplictionContext 질문
0
192
2
롬북이 안먹히는것같아요
0
156
1
인텔리제이에서스프링부트 파일 실행하면
0
240
1





