Skip to content

Commit c60836f

Browse files
[Backport-2.x] Use jsonB instead of jackson (#586) (#645)
* Use jsonB instead of jackson (#586) * Use jsonB instead of jackson Signed-off-by: Owais Kazi <[email protected]> * Resolve Jar Hell with newest versions and jakarta dependencies Signed-off-by: Daniel Widdis <[email protected]> --------- Signed-off-by: Owais Kazi <[email protected]> Signed-off-by: Daniel Widdis <[email protected]> Co-authored-by: Daniel Widdis <[email protected]> * Removed 3.x dependency Signed-off-by: owaiskazi19 <[email protected]> --------- Signed-off-by: Owais Kazi <[email protected]> Signed-off-by: Daniel Widdis <[email protected]> Signed-off-by: owaiskazi19 <[email protected]> Co-authored-by: Daniel Widdis <[email protected]>
1 parent c71020a commit c60836f

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ dependencies {
174174
implementation "org.opensearch:common-utils:${common_utils_version}"
175175
implementation 'com.amazonaws:aws-encryption-sdk-java:2.4.1'
176176
implementation 'org.bouncycastle:bcprov-jdk18on:1.77'
177-
implementation("com.fasterxml.jackson.core:jackson-annotations:${versions.jackson}")
178-
implementation("com.fasterxml.jackson.core:jackson-databind:${versions.jackson_databind}")
177+
implementation "jakarta.json.bind:jakarta.json.bind-api:3.0.0"
178+
implementation "org.glassfish:jakarta.json:2.0.1"
179+
implementation "org.eclipse:yasson:3.0.3"
179180

180181
// ZipArchive dependencies used for integration tests
181182
zipArchive group: 'org.opensearch.plugin', name:'opensearch-ml-plugin', version: "${opensearch_build}"

src/main/java/org/opensearch/flowframework/util/ParseUtils.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
*/
99
package org.opensearch.flowframework.util;
1010

11-
import com.fasterxml.jackson.core.JsonProcessingException;
12-
import com.fasterxml.jackson.databind.ObjectMapper;
13-
1411
import org.apache.logging.log4j.LogManager;
1512
import org.apache.logging.log4j.Logger;
1613
import org.opensearch.client.Client;
@@ -46,6 +43,9 @@
4643
import java.util.regex.Pattern;
4744
import java.util.stream.Collectors;
4845

46+
import jakarta.json.bind.Jsonb;
47+
import jakarta.json.bind.JsonbBuilder;
48+
4949
import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken;
5050
import static org.opensearch.flowframework.common.CommonValue.PARAMETERS_FIELD;
5151
import static org.opensearch.flowframework.common.WorkflowResources.MODEL_ID;
@@ -57,14 +57,11 @@ public class ParseUtils {
5757
private static final Logger logger = LogManager.getLogger(ParseUtils.class);
5858

5959
// Matches ${{ foo.bar }} (whitespace optional) with capturing groups 1=foo, 2=bar
60-
// private static final Pattern SUBSTITUTION_PATTERN = Pattern.compile("\\$\\{\\{\\s*(.+)\\.(.+?)\\s*\\}\\}");
6160
private static final Pattern SUBSTITUTION_PATTERN = Pattern.compile("\\$\\{\\{\\s*([\\w_]+)\\.([\\w_]+)\\s*\\}\\}");
6261
private static final Pattern JSON_ARRAY_DOUBLE_QUOTES_PATTERN = Pattern.compile("\"\\[(.*?)]\"");
6362

6463
private ParseUtils() {}
6564

66-
private static final ObjectMapper mapper = new ObjectMapper();
67-
6865
/**
6966
* Converts a JSON string into an XContentParser
7067
*
@@ -414,25 +411,28 @@ public static Object conditionallySubstitute(Object value, Map<String, WorkflowD
414411
*
415412
* @param map content map
416413
* @return instance of the string
417-
* @throws JsonProcessingException JsonProcessingException from Jackson for issues processing map
414+
* @throws Exception for issues processing map
418415
*/
419-
public static String parseArbitraryStringToObjectMapToString(Map<String, Object> map) throws JsonProcessingException {
420-
// Convert the map to a JSON string
421-
String mappedString = mapper.writeValueAsString(map);
422-
return mappedString;
416+
public static String parseArbitraryStringToObjectMapToString(Map<String, Object> map) throws Exception {
417+
try (Jsonb jsonb = JsonbBuilder.create()) {
418+
return jsonb.toJson(map);
419+
}
423420
}
424421

425422
/**
426423
* Generates a String to String map based on a Json File
427424
*
428425
* @param path file path
429426
* @return instance of the string
430-
* @throws JsonProcessingException JsonProcessingException from Jackson for issues processing map
427+
* @throws Exception for issues processing map
431428
*/
432-
public static Map<String, String> parseJsonFileToStringToStringMap(String path) throws IOException {
429+
public static Map<String, String> parseJsonFileToStringToStringMap(String path) throws Exception {
433430
String jsonContent = resourceToString(path);
434-
Map<String, String> mappedJsonFile = mapper.readValue(jsonContent, Map.class);
435-
return mappedJsonFile;
431+
try (Jsonb jsonb = JsonbBuilder.create()) {
432+
@SuppressWarnings("unchecked")
433+
Map<String, String> resultMap = jsonb.fromJson(jsonContent, Map.class);
434+
return resultMap;
435+
}
436436
}
437437

438438
/**

src/test/java/org/opensearch/flowframework/util/ParseUtilsTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void testBuildAndParseStringToStringMap() throws IOException {
8484
assertEquals(stringMap.get("one"), parsedMap.get("one"));
8585
}
8686

87-
public void testParseArbitraryStringToObjectMapToString() throws IOException {
87+
public void testParseArbitraryStringToObjectMapToString() throws Exception {
8888
Map<String, Object> map = Map.ofEntries(Map.entry("test-1", Map.of("test-1", "test-1")));
8989
String parsedMap = ParseUtils.parseArbitraryStringToObjectMapToString(map);
9090
assertEquals("{\"test-1\":{\"test-1\":\"test-1\"}}", parsedMap);

0 commit comments

Comments
 (0)