반응형
fasterxml 을 이용해 JSON 문자열을 객체로 변환하는데 단순 Snake Case 가 아닌 대문자 Snake Case 인 경우 아래 코드처럼 참고해 네이밍 전략을 수정해주면 됩니다.
2018/06/18 - [기타] - 스네이크 표기법 Snake Case
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import java.io.IOException; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy; public class Test{ private static UpperCaseStrategy UPPER_CASE = new UpperCaseStrategy(); public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(UPPER_CASE); Code code = mapper.readValue("{\"CODE\": \"A01\", \"CODE_MSG\":\"청하\"}", Code.class); System.out.println("code : " + code.getCode()); System.out.println("codeMsg : " + code.getCodeMsg()); } public static class Code { private String code; private String codeMsg; public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getCodeMsg() { return codeMsg; } public void setCodeMsg(String codeMsg) { this.codeMsg = codeMsg; } } public static class UpperCaseStrategy extends SnakeCaseStrategy { /** * */ private static final long serialVersionUID = -284516094725996654L; @Override public String translate(String input) { return super.translate(input).toUpperCase(); } } } |
반응형
'java' 카테고리의 다른 글
gc overhead limit exceeded excel download 엑셀 대용량 쓰기 (2) | 2018.08.06 |
---|---|
spring boot junit test in linux (0) | 2018.08.02 |
maven cache clear. 메이븐 캐시 클리어. (0) | 2018.07.31 |
spring boot 2.0 default connection pool (2) | 2018.07.25 |
spring resttemplate httpclient connection pool (0) | 2018.07.24 |
jackson fasterxml custom filter (exclude, masking) (0) | 2018.07.18 |
spring boot multi db and jndi in mybatis (0) | 2018.07.13 |
JNDI TEST (0) | 2018.07.09 |