Skip to content

Commit

Permalink
Use jsonB instead of jackson
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <[email protected]>
  • Loading branch information
owaiskazi19 authored and dbwiddis committed Apr 3, 2024
1 parent 33ea800 commit f48cd92
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ dependencies {
implementation 'com.amazonaws:aws-encryption-sdk-java:2.4.1'
implementation 'org.bouncycastle:bcprov-jdk18on:1.77'
api "org.apache.httpcomponents.core5:httpcore5:5.2.2"
implementation("com.fasterxml.jackson.core:jackson-annotations:${versions.jackson}")
implementation("com.fasterxml.jackson.core:jackson-databind:${versions.jackson_databind}")
implementation "jakarta.json:jakarta.json-api:2.0.1"
implementation "jakarta.json.bind:jakarta.json.bind-api:2.0.0"
implementation ("org.eclipse:yasson:2.0.2")


// ZipArchive dependencies used for integration tests
zipArchive group: 'org.opensearch.plugin', name:'opensearch-ml-plugin', version: "${opensearch_build}"
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/org/opensearch/flowframework/util/ParseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
package org.opensearch.flowframework.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -416,10 +418,16 @@ public static Object conditionallySubstitute(Object value, Map<String, WorkflowD
* @return instance of the string
* @throws JsonProcessingException JsonProcessingException from Jackson for issues processing map
*/
public static String parseArbitraryStringToObjectMapToString(Map<String, Object> map) throws JsonProcessingException {
// Convert the map to a JSON string
String mappedString = mapper.writeValueAsString(map);
return mappedString;
public static String parseArbitraryStringToObjectMapToString(Map<String, Object> map) throws Exception {
Jsonb jsonb = JsonbBuilder.create();
try {
// Convert the map to a JSON string
String jsonString = jsonb.toJson(map);
return jsonString;
} finally {
// Close the Jsonb instance
jsonb.close();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void testBuildAndParseStringToStringMap() throws IOException {
assertEquals(stringMap.get("one"), parsedMap.get("one"));
}

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

0 comments on commit f48cd92

Please sign in to comment.