초기소스
This commit is contained in:
@@ -1,23 +1,43 @@
|
||||
package com.wb.domainserver.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.wb.domainserver.exception.WnbtException;
|
||||
import com.wb.domainserver.exception.WnbtRestException;
|
||||
import com.wb.domainserver.exception.code.ErrorCode;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class WnbtResponseBody {
|
||||
private String resultCode;
|
||||
private String message;
|
||||
private Object result;
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().registerModule(new JavaTimeModule()) // LocalDateTime 지원
|
||||
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) // ISO 형식
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_NULL); // null 값 제외
|
||||
|
||||
public WnbtResponseBody(Object result) {
|
||||
this.result = result;
|
||||
|
||||
try{
|
||||
this.result = OBJECT_MAPPER.writeValueAsString(result);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error(e.getMessage());
|
||||
throw new WnbtRestException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public WnbtResponseBody(WnbtException ex){
|
||||
this.resultCode = Optional.ofNullable(ex.getCode()).orElse("FAIL");
|
||||
this.message = ex.getMessage();
|
||||
|
||||
Reference in New Issue
Block a user