반응형

 

@JsonInclude 어노데이션을 사용해 Response에 포함될 필드를 설정할 수 있다.

 

Include.ALWAYES.. 등과 함께 사용한다.

public static enum Include {
	ALWAYS,
	NON_NULL,
	NON_ABSENT,
	NON_EMPTY,
	NON_DEFAULT,
	CUSTOM,
	USE_DEFAULTS;

	private Include() {
	}
}

 

예시

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

@JsonInclude(Include.NON_NULL)
public class CategoryResponseModel {

    private final String type;
    private final String name;
    private final String icon;

    public CategoryResponseModel(CategoryDTO categoryDTO) {
        this.type = categoryDTO.getType();
        this.name = categoryDTO.getName();
        this.icon = categoryDTO.getIcon();
    }

    public String getType() {
        return type;
    }

    public String getName() {
        return name;
    }

    public String getIcon() {
        return icon;
    }
}

 

반응형
반응형

@JsonIgnore: Response에 해당 필드가 제외된다
@JsonProperty: Response에 해당 속성의 이름이 변경된다

@Getter
@Setter
public class ResponseModel {

  private String data;
  private boolean result;
  @JsonProperty("errorMessage")
  private String errorMsg;
  @JsonIgnore
  private Integer errorCode;

}

 

RESPONSE

{
  "data":"response data------",
  "result":false,
  "errorMessage":"errorrrrr"
}

 

반응형
반응형
String contextPath = ServletUriComponentsBuilder.fromCurrentContextPath().toUriString();
반응형

+ Recent posts