본문 바로가기 메뉴 바로가기

대표이미지

[JSONObject] java class 변수 Json변환 (ObjectMapper)

2023. 8. 10.

 

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JSONObject tempJob = (JSONObject)new JSONParser().parse(
	objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(tempVO));

. 단일 클래스 변환 시

.

JSONArray jarry = new JSONArray();
JSONObject tempJob = new JSONObject();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
for(MultiBoardVO tempVO : result.getMultiBoardList()) {
    tempJob = (JSONObject)new JSONParser().parse(
    	objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(tempVO));
    jarry.add(tempJob);
}

리스트 일 경우 for문에서 변환 후 JSONArray에 추가

댓글 갯수
TOP