@JsonInclude(Include.NON_NULL)
public class ErrorMessage {
}

jackson 2.2.2 에서 null 값이 데이터를 넘겨주지 않게 하기 위해서 해당 어노테이션을 사용한다. 


'Spring' 카테고리의 다른 글

Spring Rest - Content Negotiation using JSON/XML  (0) 2013.12.17

RESTful 서비스에서 하나의 리소스는 여러개의 Represenation 을 가질 수 있음.


Spring MVC 에서 Content Negotiation 이 View 를 선택하는 방법은 3가지가 있음.

1. A path extension (suffix) in the URL : favorPathExtension(true)
 - 확장자를 보고 선택하는 방법으로
http://localhost/get/user.xml or http://localhost/get/user.json
과 같은 형태.

2. A URL parameter : favorParameter(true)
 - http://localhost/get/user?format=xml 과 같은 형태로 파라미터에 전달된 값으로
선택하는 방법. format 은 변경 가능한 값(parameterName("mediaType"))

3. Accept HTTP header property : ignoreAcceptHeader(false)
 - 마지막으로 Accept 헤더에 포함 된 media type 으로 선택하는 방법이 있다.

세가지 모두 설정 된 경우 우선순위는 1~3.

Content Negotiation 설정과 무관하게 Accept 헤더는 지원 가능한
representation 으로 요청 해야 한다.
당연히 지원 불가한 타입인 경우 Content Negotiation 처리 이전에 HttpMediaTypeNotAcceptableException 이 발생한다.

참조 : http://theblasfrompas.blogspot.kr/2013/10/spring-mvc-rest-content-negotiation.html

'Spring' 카테고리의 다른 글

Json Null 값 안보이게 하기  (0) 2014.01.27

+ Recent posts