728x90 반응형 SMALL IT/JAVA46 Gson Serialize 시 예외 시키기 (@Expose) 객체를 복사하는 방법은 여러 방법이 있다. Gson 을 이용하여 복사할 수도 있는데 이때 복사하고 싶지 않은 변수에 대해서는 @Expose 어노테이션을 사용한다. 그런데 정상적으로 동작하지 않아서 예외처리 하는 전략클래스를 만들어 사용 했더니.. 잘된다. /** * Gson serialize, deserialize 시 @Expose annotation 이 있는 Field 제외 전략 클래스 * @author yhkim * */ public class GsonSkipExposeAnnotationStrategy implements ExclusionStrategy { @Override public boolean shouldSkipField(FieldAttributes f) { return (null != f.g.. 2019. 11. 28. Rest API QueryString Parsing for MyBatis REST API 를 만들다 보면 상세한 검색조건을 처리해야 하는 일이 발생하는데 URI 에 포함된 querystring 을 어떻게 처리해야 좋을지 고민 된다. JPA, QueryDSL 등과 같은 ORM 에 대해서는 찾아보면 많은 라이브러리, Framework 들이 존재하기 때문에 적당한 녀석을 찾아서 사용하면 된다. ex. https://docs.spring.io/spring-data/rest/docs/current/reference/html/#repository-resources.query-method-resource ex. https://www.baeldung.com/rest-api-search-querydsl-web-in-spring-data-jpa ex. https://www.baeldung.co.. 2019. 9. 24. Gson LocalDateTime 처리(BEGIN_OBJECT but was STRING) Date 와 관련된 값들은 Java8 부터 지원하는 LocalDateTime 을 주로 사용한다. API 를 통해 객체 정보를 요청하고 수신할때 serialize, deserialize 하게 되는데 이때 google의 Gson을 많이 사용한다. 그런데 Gson 은 LocalDateTime 을 알지 못하기 때문에 LocalDateTime 에 대한 구문 분석을 하지 못한다. Expected BEGIN_OBJECT but was STRING .... 18:05 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [/decide7] threw exception .. 2019. 9. 18. ConcurrentModificationException 데이터를 순회하면서 특정 data를 조작(삭제)하고 싶을 때 발생한다. Iterator it = map.entrySet().iterator(); while (it.hasNext()) { Entry entry = it.next(); if (entry != null && entry.getValue().compareTo(actualExpiredTime) < 0) { map.remove(entry.getKey()); } } Java 공식 문서를 보면 Iterator 의 remove를 이용하는 것이 Collection을 순회하면서 element를 삭제하는 유일하게 안전한 방법이라고 가이드 하고 있다. 그래서 소스코드를 바꿔본다. Iterator it = map.entrySet().iterator(); while .. 2019. 5. 21. 이전 1 ··· 3 4 5 6 7 8 9 ··· 12 다음 728x90 반응형 LIST