@@ -49,7 +49,6 @@ public class JSONYAMLSchemaValidator extends AbstractMessageValidator {
4949
5050 private final YAMLFactory factory = YAMLFactory .builder ().enable (STRICT_DUPLICATE_DETECTION ).build ();
5151 private final ObjectMapper yamlObjectMapper = new ObjectMapper (factory );
52- private final ObjectMapper jsonObjectMapper = new ObjectMapper ();
5352
5453 public static final String SCHEMA_VERSION_2020_12 = "2020-12" ;
5554
@@ -63,11 +62,6 @@ public class JSONYAMLSchemaValidator extends AbstractMessageValidator {
6362
6463 private Map <String , String > schemaMappings = new HashMap <>();
6564
66- /**
67- * JsonSchemaFactory instances are thread-safe provided its configuration is not modified.
68- */
69- SchemaRegistry jsonSchemaFactory ;
70-
7165 /**
7266 * JsonSchema instances are thread-safe provided its configuration is not modified.
7367 */
@@ -100,22 +94,25 @@ public String getName() {
10094 public void init () {
10195 super .init ();
10296
103- jsonSchemaFactory = SchemaRegistry .withDefaultDialect (schemaId , b -> b .schemaLoader (SchemaLoader .builder ()
104- .schemaIdResolvers (r -> r .mappings (schemaMappings ))
105- .resourceLoaders (rl -> rl .values (list -> list .addFirst (new MembraneSchemaLoader (resolver ))))
106- .build ()));
107-
10897 try (InputStream in = resolver .resolve (jsonSchema )) {
109- InputFormat schemaFormat =
110- (jsonSchema .endsWith (".yaml" ) || jsonSchema .endsWith (".yml" )) ? YAML : JSON ;
111-
112- schema = jsonSchemaFactory .getSchema (SchemaLocation .of (jsonSchema ), in , schemaFormat );
98+ schema = getJsonSchemaFactory ().getSchema (SchemaLocation .of (jsonSchema ), in , getSchemaFormat ());
11399 schema .initializeValidators ();
114100 } catch (IOException e ) {
115101 throw new RuntimeException ("Cannot read JSON Schema from: " + jsonSchema , e );
116102 }
117103 }
118104
105+ private @ NotNull InputFormat getSchemaFormat () {
106+ return (jsonSchema .endsWith (".yaml" ) || jsonSchema .endsWith (".yml" )) ? YAML : JSON ;
107+ }
108+
109+ private SchemaRegistry getJsonSchemaFactory () {
110+ return SchemaRegistry .withDefaultDialect (schemaId , b -> b .schemaLoader (SchemaLoader .builder ()
111+ .schemaIdResolvers (r -> r .mappings (schemaMappings ))
112+ .resourceLoaders (rl -> rl .values (list -> list .addFirst (new MembraneSchemaLoader (resolver ))))
113+ .build ()));
114+ }
115+
119116 public Outcome validateMessage (Exchange exc , Flow flow ) throws Exception {
120117 return validateMessage (exc , flow , UTF_8 );
121118 }
0 commit comments