open API

Map <=> Object & JSON String <=> Object(or List)

張's blog 2021. 4. 15. 00:23


- 필드명은 같지만 클래스가 다른 객체 복사
ObjectCopyTools 참조
https://stackoverflow.com/questions/5937567/copy-pojo-content-from-one-bean-to-another



- Map <=> Object
https://yjkim97.tistory.com/m/9

 

[JAVA] Map to Object, Object to Map

Object를 Map으로 변환, Map을 Object로 변환하는 Util 사용 객체 PropertyDescriptor Method Object method invoke (setMethod) private static void invokeMethodSiently(Object obj, Method m, Object val) { t..

yjkim97.tistory.com


- RefelectionUtil

https://yjkim97.tistory.com/m/19

 

[JAVA] ReflectionUtil

[util] - ReflectionUtil.java package com.kt.tbb.iptv.coupon.framework.util; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.Pr..

yjkim97.tistory.com

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

 

How to convert JSON string into List of Java object?

This is my JSON Array :- [ { "firstName" : "abc", "lastName" : "xyz" }, { "firstName" : "pqr", "lastName" : "str" } ] I have this in my String

stackoverflow.com

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/

 

Jackson - Convert JSON array string to List - Mkyong.com

- Jackson - Convert JSON array string to List

mkyong.com


https://unlimitedcoding.tistory.com/m/14

 

[JAVA] json String to List map

String to map Map map = new ObjectMapper().readValue(스트링변수, new TypeReference >() { }); String to List map List > paramMap = new ObjectMapper().readValue(스트링변수, new TypeReference >>(){});..

unlimitedcoding.tistory.com


- Ignore NULL Fields
https://www.baeldung.com/jackson-ignore-null-fields

 

Ignore Null Fields with Jackson | Baeldung

Ignore null fields with Jackson 2 - either globally, per class or even per field.

www.baeldung.com


- jackson 설명
https://umbum.dev/880

 

[Java] Jackson ObjectMapper Serialization

```kt val MY_OBJECT_MAPPER = jacksonObjectMapper() .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .setSerializationInclusion(Include.NON_NULL) .setPropertyNamingStrategy(Proper..

umbum.dev


- @JsonProperty, @JsonIgnore
https://stackoverflow.com/questions/60185183/how-to-ignore-jsonproperty-while-converting-object-to-map-by-jackson

 

How to ignore @JsonProperty while converting object to map by Jackson

For example, I have a class User which has only 2 fields - name and identification which annotated by @JsonProperty respectively. And I use Jackson to convert this object to a Map, but the result i...

stackoverflow.com


- @JsonFilter를 이용한 조건에 맞는 필드만 json변환
https://jsonobject.tistory.com/258

 

Jackson, 커스텀 @JsonFilter로 조건에 맞는 필드만 JSON 변환하기

개요 Jackson은 Java 진영의 대표적인 POJO-JSON 상호 변환 라이브러리이다. 이번 글에서는 @JsonFilter 를 이용하여 POJO 오브젝트의 필드 값을 기준으로 조건에 맞는 필드만 선택적으로 JSON으로 변환하는

jsonobject.tistory.com

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

 

How to registrer custom jackson filter in spring application?

I have read following question: https://stackoverflow.com/a/25609465/2674303 I have spring-mvc application. If I annotate controller method with @ResponseBody annotation and return object inside ...

stackoverflow.com

SimpleFilterProvider filterProvider = SimpleFilterProvider();
filterProvider.setFailOnUnknown(false);

ObjectMapper mapper = new ObjectMapper();
mapper.setFilterProvider(filterProvider);



- Map의 entrySet, keySet
https://tychejin.tistory.com/31

 

[Java] Map 전체 출력(entrySet, keySet, Iterator, Lambda, Stream)

Map 전체 출력 Map에 값을 전체 출력하기 위해서는 entrySet(), keySet() 메소드를 사용하면 되는데 entrySet() 메서드는 key와 value의 값이 모두 필요한 경우 사용하고, keySet() 메서드는 key의 값만 필요한 경

tychejin.tistory.com