From 2d501e19e43f7c708335b699b9857bcf9156d114 Mon Sep 17 00:00:00 2001 From: wangqingshuai Date: Mon, 25 Dec 2023 20:41:42 +0800 Subject: [PATCH] [refactor] replace minidev json api to jackson api --- .../online/adapter/pg/PgJsonReader.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/ecnu/db/analyzer/online/adapter/pg/PgJsonReader.java b/src/main/java/ecnu/db/analyzer/online/adapter/pg/PgJsonReader.java index 5157de22..432df778 100644 --- a/src/main/java/ecnu/db/analyzer/online/adapter/pg/PgJsonReader.java +++ b/src/main/java/ecnu/db/analyzer/online/adapter/pg/PgJsonReader.java @@ -1,10 +1,11 @@ package ecnu.db.analyzer.online.adapter.pg; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.Option; -import net.minidev.json.JSONObject; import java.util.Collections; import java.util.LinkedHashMap; @@ -76,8 +77,8 @@ static StringBuilder getRootPath() { return new StringBuilder("$.[0]['Plan']"); } - static String formatPlan(String query){ - return "[{\"Plan\":" + query + "}]"; + static String formatPlan(String query) { + return "[{\"Plan\":" + query + "}]"; } // deal with subPlan @@ -100,7 +101,11 @@ static int readPlansCount(StringBuilder path) { static String readPlan(StringBuilder path, int index) { LinkedHashMap data = readContext.read(path + "['Plans'][" + index + "]"); - return JSONObject.toJSONString(data); + try { + return new ObjectMapper().writeValueAsString(data); + } catch (JsonProcessingException e) { + throw new IllegalStateException(e); + } } static String readSubPlanIndex(StringBuilder path) { @@ -117,7 +122,11 @@ static String readSubPlanIndex(StringBuilder path) { static String readTheWholePlan() { LinkedHashMap data = readContext.read("$.[0]"); - return "[" + JSONObject.toJSONString(data) + "]"; + try { + return "[" + new ObjectMapper().writeValueAsString(data) + "]"; + } catch (JsonProcessingException e) { + throw new IllegalStateException(e); + } } static String readSubPlanIndex(StringBuilder path, int index) {