18
18
import com .networknt .schema .JsonSchemaFactory ;
19
19
import com .networknt .schema .SpecVersion ;
20
20
import io .burt .jmespath .JmesPath ;
21
- import io .burt .jmespath .RuntimeConfiguration ;
22
21
import io .burt .jmespath .function .BaseFunction ;
23
- import io .burt .jmespath .function .FunctionRegistry ;
24
- import io .burt .jmespath .jackson .JacksonRuntime ;
25
- import software .amazon .lambda .powertools .validation .jmespath .Base64Function ;
26
- import software .amazon .lambda .powertools .validation .jmespath .Base64GZipFunction ;
27
-
28
- import static com .fasterxml .jackson .databind .DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES ;
22
+ import software .amazon .lambda .powertools .utilities .JsonConfig ;
23
+ import software .amazon .lambda .powertools .utilities .jmespath .Base64Function ;
24
+ import software .amazon .lambda .powertools .utilities .jmespath .Base64GZipFunction ;
29
25
30
26
/**
31
27
* Use this if you need to customize some part of the JSON Schema validation
32
- * (eg. specification version, Jackson ObjectMapper, or adding functions to JMESPath)
28
+ * (eg. specification version, Jackson ObjectMapper, or adding functions to JMESPath).
29
+ *
30
+ * For everything but the validation features (factory, schemaVersion), {@link ValidationConfig}
31
+ * is just a wrapper of {@link JsonConfig}.
33
32
*/
34
33
public class ValidationConfig {
35
34
private ValidationConfig () {
@@ -43,24 +42,9 @@ public static ValidationConfig get() {
43
42
return ConfigHolder .instance ;
44
43
}
45
44
46
- private static final ThreadLocal <ObjectMapper > om = ThreadLocal .withInitial (() -> {
47
- ObjectMapper objectMapper = new ObjectMapper ();
48
- objectMapper .configure (FAIL_ON_UNKNOWN_PROPERTIES , false );
49
- return objectMapper ;
50
- });
51
-
52
45
private SpecVersion .VersionFlag jsonSchemaVersion = SpecVersion .VersionFlag .V7 ;
53
46
private JsonSchemaFactory factory = JsonSchemaFactory .getInstance (jsonSchemaVersion );
54
47
55
- private final FunctionRegistry defaultFunctions = FunctionRegistry .defaultRegistry ();
56
- private final FunctionRegistry customFunctions = defaultFunctions .extend (
57
- new Base64Function (),
58
- new Base64GZipFunction ());
59
- private final RuntimeConfiguration configuration = new RuntimeConfiguration .Builder ()
60
- .withFunctionRegistry (customFunctions )
61
- .build ();
62
- private JmesPath <JsonNode > jmesPath = new JacksonRuntime (configuration , getObjectMapper ());
63
-
64
48
/**
65
49
* Set the version of the json schema specifications (default is V7)
66
50
*
@@ -85,13 +69,7 @@ public SpecVersion.VersionFlag getSchemaVersion() {
85
69
* @param <T> Must extends {@link BaseFunction}
86
70
*/
87
71
public <T extends BaseFunction > void addFunction (T function ) {
88
- FunctionRegistry functionRegistryWithExtendedFunctions = configuration .functionRegistry ().extend (function );
89
-
90
- RuntimeConfiguration updatedConfig = new RuntimeConfiguration .Builder ()
91
- .withFunctionRegistry (functionRegistryWithExtendedFunctions )
92
- .build ();
93
-
94
- jmesPath = new JacksonRuntime (updatedConfig , getObjectMapper ());
72
+ JsonConfig .get ().addFunction (function );
95
73
}
96
74
97
75
/**
@@ -109,7 +87,7 @@ public JsonSchemaFactory getFactory() {
109
87
* @return the {@link JmesPath}
110
88
*/
111
89
public JmesPath <JsonNode > getJmesPath () {
112
- return jmesPath ;
90
+ return JsonConfig . get (). getJmesPath () ;
113
91
}
114
92
115
93
/**
@@ -118,6 +96,6 @@ public JmesPath<JsonNode> getJmesPath() {
118
96
* @return the {@link ObjectMapper} to serialize / deserialize JSON
119
97
*/
120
98
public ObjectMapper getObjectMapper () {
121
- return om .get ();
99
+ return JsonConfig .get (). getObjectMapper ();
122
100
}
123
101
}
0 commit comments