@Override public String getData(Gson gson) { String data; if (sortList.isEmpty() && includePatternList.isEmpty() && excludePatternList.isEmpty()) { data = query; } else { JsonObject queryObject = gson.fromJson(query, JsonObject.class); if (queryObject == null) { queryObject = new JsonObject(); } if (!sortList.isEmpty()) { JsonArray sortArray = normalizeSortClause(queryObject); for (Sort sort : sortList) { sortArray.add(sort.toJsonObject()); } } if (!includePatternList.isEmpty() || !excludePatternList.isEmpty()) { JsonObject sourceObject = normalizeSourceClause(queryObject); addPatternListToSource(sourceObject, "includes", includePatternList); addPatternListToSource(sourceObject, "excludes", excludePatternList); } data = gson.toJson(queryObject); } return data; }
@Override public String getData(Gson gson) { String data; if (sortList.isEmpty() && includePatternList.isEmpty() && excludePatternList.isEmpty()) { data = query; } else { JsonObject queryObject = gson.fromJson(query, JsonObject.class); if (queryObject == null) { queryObject = new JsonObject(); } if (!sortList.isEmpty()) { JsonArray sortArray = normalizeSortClause(queryObject); for (Sort sort : sortList) { sortArray.add(sort.toJsonObject()); } } if (!includePatternList.isEmpty() || !excludePatternList.isEmpty()) { JsonObject sourceObject = normalizeSourceClause(queryObject); addPatternListToSource(sourceObject, "includes", includePatternList); addPatternListToSource(sourceObject, "excludes", excludePatternList); } data = gson.toJson(queryObject); } return data; }
@Override public String getData(ObjectMapper objectMapper) throws IOException { String data; if (sortList.isEmpty() && includePatternList.isEmpty() && excludePatternList.isEmpty()) { data = query; } else { ObjectNode queryObject = (ObjectNode) objectMapper.readTree(query); if (queryObject == null) { queryObject = objectMapper.createObjectNode(); } if (!sortList.isEmpty()) { ArrayNode sortArray = normalizeSortClause(queryObject, objectMapper); for (Sort sort : sortList) { sortArray.add(sort.toJsonObject(objectMapper)); } } if (!includePatternList.isEmpty() || !excludePatternList.isEmpty()) { ObjectNode sourceObject = normalizeSourceClause(queryObject, objectMapper); addPatternListToSource(sourceObject, "include", includePatternList, objectMapper); addPatternListToSource(sourceObject, "exclude", excludePatternList, objectMapper); } data = objectMapper.writeValueAsString(queryObject); } return data; }