[JSON] Build Nested ObjectNode
다음과 같이 object가 중첩된 json을 만들어 보자.
Jackson 코드는 아래와 같다.
{ "employee": { "company": "MyCom", "teams": { "team1": { "name": "AAAA", "location": "sector-a" }, "team2": { "name": "BBBB", "location": "sector-b" } } } }
Jackson 코드는 아래와 같다.
ObjectMapper mapper = new ObjectMapper(); ObjectNode root = mapper.createObjectNode(); ObjectNode employee = root.putObject("employee"); emplyee.put("compayn", "MyCom"); ObjectNode teams = employee.putObject("teams"); ObjectNode team1 = teams.putObject("team1"); team1.put("name", "AAAA"); team1.put("location", "sector-a"); ObjectNode team2 = teams.putObject("team2"); team2.put("name", "BBBB"); team2.put("location", "sector-b");
댓글
댓글 쓰기