지정한 depth 까지만 object 로 변환하고 나머지는 기존 json string 을 유지해야 할 경우
String test_obj = "{\"title\":\"타이틀\",\"location\":\"회의실\",\"contact\":[\"김과장\",\"이과장\",\"박과장\"]}";
System.out.println(test_obj);
ObjectMapper mapper = new ObjectMapper();
Map<String,Object> sample_map = new HashMap<String,Object>();
sample_map.put("test", "value");
sample_map = mapper.readValue(test_obj, new TypeReference<HashMap<String,JsonNode>>(){});
for(Entry<String, Object> entry : sample_map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
System.out.println(String.format("[key : %s] - [value : %s]", key,value));
}
----------------------------------------result------------------------------------
{"title":"타이틀","location":"회의실","contact":["김과장","이과장","박과장"]}
[key : title] - [value : "타이틀"]
[key : location] - [value : "회의실"]
[key : contact] - [value : ["김과장","이과장","박과장"]]
'프로그램 > Java' 카테고리의 다른 글
java 랜덤 범위 지정 (0) | 2014.10.24 |
---|---|
spring cross-domain filter (0) | 2014.07.22 |
직렬화 (Serialize) (0) | 2014.02.21 |
자바 모니터링 툴 visualVM visualGC (0) | 2013.09.24 |
android adb shell (0) | 2012.11.02 |