|
12 | 12 | import com.jayway.jsonpath.Configuration; |
13 | 13 | import com.jayway.jsonpath.JsonPath; |
14 | 14 | import com.jayway.jsonpath.Option; |
15 | | -import com.jayway.jsonpath.spi.json.JacksonJsonNodeJsonProvider; |
16 | | -import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider; |
17 | 15 | import java.io.IOException; |
18 | 16 | import java.util.ArrayList; |
19 | 17 | import java.util.Arrays; |
20 | 18 | import java.util.List; |
| 19 | +import java.util.Map; |
21 | 20 | import java.util.function.Predicate; |
22 | 21 | import java.util.regex.Pattern; |
23 | 22 | import java.util.regex.PatternSyntaxException; |
24 | 23 | import java.util.stream.Collectors; |
25 | | -import java.util.stream.Stream; |
26 | 24 |
|
27 | 25 | public class SegmentEvaluator { |
28 | 26 | private static ObjectMapper mapper = new ObjectMapper(); |
29 | | - private static Configuration jacksonNodeConf = Configuration.builder() |
30 | | - .jsonProvider(new JacksonJsonNodeJsonProvider()) |
31 | | - .mappingProvider(new JacksonMappingProvider(mapper)) |
32 | | - .options(Option.DEFAULT_PATH_LEAF_TO_NULL) |
33 | | - .build(); |
| 27 | + private static Configuration jsonPathConfiguration = Configuration |
| 28 | + .defaultConfiguration() |
| 29 | + .setOptions(Option.SUPPRESS_EXCEPTIONS); |
34 | 30 |
|
35 | 31 | /** |
36 | 32 | * Check if context is in segment. |
@@ -107,7 +103,7 @@ private static Boolean contextMatchesCondition( |
107 | 103 | } |
108 | 104 |
|
109 | 105 | if (!(contextValue instanceof Boolean)) { |
110 | | - contextValue = contextValue.toString(); |
| 106 | + contextValue = String.valueOf(contextValue); |
111 | 107 | } |
112 | 108 |
|
113 | 109 | return conditionList.contains(contextValue); |
@@ -198,7 +194,10 @@ private static Boolean contextMatchesCondition( |
198 | 194 | */ |
199 | 195 | private static Object getContextValue(EvaluationContext context, String property) { |
200 | 196 | if (property.startsWith("$.")) { |
201 | | - return JsonPath.using(jacksonNodeConf).parse(mapper.valueToTree(context)).read(property); |
| 197 | + return JsonPath |
| 198 | + .using(jsonPathConfiguration) |
| 199 | + .parse(mapper.convertValue(context, Map.class)) |
| 200 | + .read(property); |
202 | 201 | } |
203 | 202 | if (context.getIdentity() != null) { |
204 | 203 | return context.getIdentity().getTraits().getAdditionalProperties().get(property); |
|
0 commit comments