Map <=> Object & JSON String <=> Object(or List)
- 필드명은 같지만 클래스가 다른 객체 복사
ObjectCopyTools 참조
https://stackoverflow.com/questions/5937567/copy-pojo-content-from-one-bean-to-another
- Map <=> Object
https://yjkim97.tistory.com/m/9
- RefelectionUtil
https://yjkim97.tistory.com/m/19
SampleVO object = new SampleVO();
java beans.BeanInfo beanInfo = java.beans.Introspector.getBeanInfo(object.getClass());
java.beans.PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
for(PropertyDescriptor pd : pds) {
Class<?> classType = pd.getPropertyType();
Method getMethod = pd.gerReadMethod(); // get method
Methid setMethod = pd.getWriteMethod(); // set method
}
- org.apache.commin.beanutils.PropertyUtils
java.beans.PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(클래스타입);
- org.springframework.beans.BeanUtils
org.springframework.beans.BeanUtils.getPropertyDescriptors(클래스타입);
- JSON String <=> List<E>
https://stackoverflow.com/questions/44589381/how-to-convert-json-string-into-list-of-java-object
final ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new Jdk8Module());
CollectionType listType = mapper.getTypeFactory().constructCollectionType(List.class, SampleVO);
List<SampleVO> list = mapper.readValue(jsonStr, listType);
readValue(json, new TypeReference<List<Map>>(){});
https://mkyong.com/java/jackson-convert-json-array-string-to-list/
https://unlimitedcoding.tistory.com/m/14
- Ignore NULL Fields
https://www.baeldung.com/jackson-ignore-null-fields
- jackson 설명
https://umbum.dev/880
- @JsonProperty, @JsonIgnore
https://stackoverflow.com/questions/60185183/how-to-ignore-jsonproperty-while-converting-object-to-map-by-jackson
- @JsonFilter를 이용한 조건에 맞는 필드만 json변환
https://jsonobject.tistory.com/258
SimpleFilterProvider filterProvider = SimpleFilterProvider();
filterProvider.setFailOnUnknown(false);
filterProvider.addFilter("필터아이디", new SampleFliter());
ObjectMapper mapper = new ObjectMapper();
mapper.setFilterProvider(filterProvider);
- responseBody 를 이용한 json 변환시 default filter 적용시키기
https://stackoverflow.com/questions/31029370/how-to-registrer-custom-jackson-filter-in-spring-application/31056284#31056284
SimpleFilterProvider filterProvider = SimpleFilterProvider();
filterProvider.setFailOnUnknown(false);
ObjectMapper mapper = new ObjectMapper();
mapper.setFilterProvider(filterProvider);
- Map의 entrySet, keySet
https://tychejin.tistory.com/31