Skip to content

Commit

Permalink
[refactor] replace minidev json api to jackson api
Browse files Browse the repository at this point in the history
  • Loading branch information
ylht committed Dec 25, 2023
1 parent e0ebb34 commit 2d501e1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/main/java/ecnu/db/analyzer/online/adapter/pg/PgJsonReader.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -100,7 +101,11 @@ static int readPlansCount(StringBuilder path) {

static String readPlan(StringBuilder path, int index) {
LinkedHashMap<String, Object> 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) {
Expand All @@ -117,7 +122,11 @@ static String readSubPlanIndex(StringBuilder path) {

static String readTheWholePlan() {
LinkedHashMap<String, Object> 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) {
Expand Down

0 comments on commit 2d501e1

Please sign in to comment.