8
8
*/
9
9
package org .opensearch .flowframework .util ;
10
10
11
- import com .fasterxml .jackson .core .JsonProcessingException ;
12
- import com .fasterxml .jackson .databind .ObjectMapper ;
13
-
14
11
import org .apache .logging .log4j .LogManager ;
15
12
import org .apache .logging .log4j .Logger ;
16
13
import org .opensearch .client .Client ;
46
43
import java .util .regex .Pattern ;
47
44
import java .util .stream .Collectors ;
48
45
46
+ import jakarta .json .bind .Jsonb ;
47
+ import jakarta .json .bind .JsonbBuilder ;
48
+
49
49
import static org .opensearch .core .xcontent .XContentParserUtils .ensureExpectedToken ;
50
50
import static org .opensearch .flowframework .common .CommonValue .PARAMETERS_FIELD ;
51
51
import static org .opensearch .flowframework .common .WorkflowResources .MODEL_ID ;
@@ -57,14 +57,11 @@ public class ParseUtils {
57
57
private static final Logger logger = LogManager .getLogger (ParseUtils .class );
58
58
59
59
// Matches ${{ foo.bar }} (whitespace optional) with capturing groups 1=foo, 2=bar
60
- // private static final Pattern SUBSTITUTION_PATTERN = Pattern.compile("\\$\\{\\{\\s*(.+)\\.(.+?)\\s*\\}\\}");
61
60
private static final Pattern SUBSTITUTION_PATTERN = Pattern .compile ("\\ $\\ {\\ {\\ s*([\\ w_]+)\\ .([\\ w_]+)\\ s*\\ }\\ }" );
62
61
private static final Pattern JSON_ARRAY_DOUBLE_QUOTES_PATTERN = Pattern .compile ("\" \\ [(.*?)]\" " );
63
62
64
63
private ParseUtils () {}
65
64
66
- private static final ObjectMapper mapper = new ObjectMapper ();
67
-
68
65
/**
69
66
* Converts a JSON string into an XContentParser
70
67
*
@@ -414,25 +411,28 @@ public static Object conditionallySubstitute(Object value, Map<String, WorkflowD
414
411
*
415
412
* @param map content map
416
413
* @return instance of the string
417
- * @throws JsonProcessingException JsonProcessingException from Jackson for issues processing map
414
+ * @throws Exception for issues processing map
418
415
*/
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
+ }
423
420
}
424
421
425
422
/**
426
423
* Generates a String to String map based on a Json File
427
424
*
428
425
* @param path file path
429
426
* @return instance of the string
430
- * @throws JsonProcessingException JsonProcessingException from Jackson for issues processing map
427
+ * @throws Exception for issues processing map
431
428
*/
432
- public static Map <String , String > parseJsonFileToStringToStringMap (String path ) throws IOException {
429
+ public static Map <String , String > parseJsonFileToStringToStringMap (String path ) throws Exception {
433
430
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
+ }
436
436
}
437
437
438
438
/**
0 commit comments