This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push: new ddd1045e57a CAMEL-20980 Add object mapper component option for json validator (#1177) ddd1045e57a is described below commit ddd1045e57a26f5f6688d19067a143610ec7be4d Author: Alvin Kwekel <al...@liberition.com> AuthorDate: Wed Jul 17 11:24:35 2024 +0200 CAMEL-20980 Add object mapper component option for json validator (#1177) Co-authored-by: Alvin Kwekel <am.kwe...@minvws.nl> --- .../catalog/components/json-validator.json | 6 +- .../src/main/docs/json-validator.json | 6 ++ .../JsonValidatorComponentAutoConfiguration.java | 2 +- .../JsonValidatorComponentConfiguration.java | 14 +++++ .../JsonValidatorComponentConverter.java | 63 +++++++++++++++++++++ ...rk.boot.autoconfigure.AutoConfiguration.imports | 3 +- tooling/camel-spring-boot-dependencies/pom.xml | 66 +++++++++++----------- 7 files changed, 123 insertions(+), 37 deletions(-) diff --git a/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/json-validator.json b/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/json-validator.json index 9f7e9372c1d..d08f5c07c9c 100644 --- a/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/json-validator.json +++ b/catalog/camel-catalog-provider-springboot/src/main/resources/org/apache/camel/springboot/catalog/components/json-validator.json @@ -24,7 +24,8 @@ }, "componentProperties": { "lazyStartProducer": { "index": 0, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail [...] - "autowiredEnabled": { "index": 1, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...] + "autowiredEnabled": { "index": 1, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching t [...] + "objectMapper": { "index": 2, "kind": "property", "displayName": "Object Mapper", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.fasterxml.jackson.databind.ObjectMapper", "deprecated": false, "autowired": true, "secret": false, "description": "To use a custom ObjectMapper" } }, "properties": { "resourceUri": { "index": 0, "kind": "path", "displayName": "Resource Uri", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "supportFileReference": true, "description": "Path to the resource. You can prefix with: classpath, file, http, ref, or bean. classpath, file and http loads the resource using these protocols (classpath is default). ref will look [...] @@ -37,6 +38,7 @@ "disabledDeserializationFeatures": { "index": 7, "kind": "parameter", "displayName": "Disabled Deserialization Features", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Comma-separated list of Jackson DeserializationFeature enum values which will be disabled for parsing exchange body" }, "enabledDeserializationFeatures": { "index": 8, "kind": "parameter", "displayName": "Enabled Deserialization Features", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Comma-separated list of Jackson DeserializationFeature enum values which will be enabled for parsing exchange body" }, "errorHandler": { "index": 9, "kind": "parameter", "displayName": "Error Handler", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.jsonvalidator.JsonValidatorErrorHandler", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom ValidatorErrorHandler. The default error handler captures the errors and throws an exception." }, - "uriSchemaLoader": { "index": 10, "kind": "parameter", "displayName": "Uri Schema Loader", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.jsonvalidator.JsonUriSchemaLoader", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom schema loader allowing for adding custom format validation. The default implementation will create a schema loader that tries to determine the schema ve [...] + "objectMapper": { "index": 10, "kind": "parameter", "displayName": "Object Mapper", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.fasterxml.jackson.databind.ObjectMapper", "deprecated": false, "autowired": false, "secret": false, "description": "The used Jackson object mapper" }, + "uriSchemaLoader": { "index": 11, "kind": "parameter", "displayName": "Uri Schema Loader", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.jsonvalidator.JsonUriSchemaLoader", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom schema loader allowing for adding custom format validation. The default implementation will create a schema loader that tries to determine the schema ve [...] } } diff --git a/components-starter/camel-json-validator-starter/src/main/docs/json-validator.json b/components-starter/camel-json-validator-starter/src/main/docs/json-validator.json index 7f13d78d4c9..0759731af7a 100644 --- a/components-starter/camel-json-validator-starter/src/main/docs/json-validator.json +++ b/components-starter/camel-json-validator-starter/src/main/docs/json-validator.json @@ -37,6 +37,12 @@ "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the [...] "sourceType": "org.apache.camel.component.jsonvalidator.springboot.JsonValidatorComponentConfiguration", "defaultValue": false + }, + { + "name": "camel.component.json-validator.object-mapper", + "type": "com.fasterxml.jackson.databind.ObjectMapper", + "description": "To use a custom ObjectMapper. The option is a com.fasterxml.jackson.databind.ObjectMapper type.", + "sourceType": "org.apache.camel.component.jsonvalidator.springboot.JsonValidatorComponentConfiguration" } ], "hints": [] diff --git a/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentAutoConfiguration.java b/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentAutoConfiguration.java index 7fa8da7e972..0a666fc1ac0 100644 --- a/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentAutoConfiguration.java +++ b/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentAutoConfiguration.java @@ -42,7 +42,7 @@ import org.springframework.context.annotation.Lazy; @Conditional(ConditionalOnCamelContextAndAutoConfigurationBeans.class) @EnableConfigurationProperties({ComponentConfigurationProperties.class,JsonValidatorComponentConfiguration.class}) @ConditionalOnHierarchicalProperties({"camel.component", "camel.component.json-validator"}) -@AutoConfigureAfter(CamelAutoConfiguration.class) +@AutoConfigureAfter({CamelAutoConfiguration.class, JsonValidatorComponentConverter.class}) public class JsonValidatorComponentAutoConfiguration { @Autowired diff --git a/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentConfiguration.java b/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentConfiguration.java index 470620987cf..1f2a6af72b2 100644 --- a/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentConfiguration.java +++ b/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentConfiguration.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.jsonvalidator.springboot; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -54,6 +55,11 @@ public class JsonValidatorComponentConfiguration * etc. */ private Boolean autowiredEnabled = true; + /** + * To use a custom ObjectMapper. The option is a + * com.fasterxml.jackson.databind.ObjectMapper type. + */ + private ObjectMapper objectMapper; public Boolean getLazyStartProducer() { return lazyStartProducer; @@ -70,4 +76,12 @@ public class JsonValidatorComponentConfiguration public void setAutowiredEnabled(Boolean autowiredEnabled) { this.autowiredEnabled = autowiredEnabled; } + + public ObjectMapper getObjectMapper() { + return objectMapper; + } + + public void setObjectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } } \ No newline at end of file diff --git a/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentConverter.java b/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentConverter.java new file mode 100644 index 00000000000..f0157a1897e --- /dev/null +++ b/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentConverter.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jsonvalidator.springboot; + +import java.util.LinkedHashSet; +import java.util.Set; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.convert.TypeDescriptor; +import org.springframework.core.convert.converter.GenericConverter; +import org.springframework.stereotype.Component; + +/** + * Generated by camel-package-maven-plugin - do not edit this file! + */ +@Configuration(proxyBeanMethods = false) +@ConfigurationPropertiesBinding +@Component +public class JsonValidatorComponentConverter implements GenericConverter { + + @Autowired + private ApplicationContext applicationContext; + + public Set<ConvertiblePair> getConvertibleTypes() { + Set<ConvertiblePair> answer = new LinkedHashSet<>(); + answer.add(new ConvertiblePair(String.class, com.fasterxml.jackson.databind.ObjectMapper.class)); + return answer; + } + + public Object convert( + Object source, + TypeDescriptor sourceType, + TypeDescriptor targetType) { + if (source == null) { + return null; + } + String ref = source.toString(); + if (!ref.startsWith("#")) { + return null; + } + ref = ref.startsWith("#bean:") ? ref.substring(6) : ref.substring(1); + switch (targetType.getName()) { + case "com.fasterxml.jackson.databind.ObjectMapper": return applicationContext.getBean(ref, com.fasterxml.jackson.databind.ObjectMapper.class); + } + return null; + } +} \ No newline at end of file diff --git a/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 1c77215cd8f..cabe2fad058 100644 --- a/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -15,4 +15,5 @@ ## limitations under the License. ## --------------------------------------------------------------------------- -org.apache.camel.component.jsonvalidator.springboot.JsonValidatorComponentAutoConfiguration \ No newline at end of file +org.apache.camel.component.jsonvalidator.springboot.JsonValidatorComponentAutoConfiguration +org.apache.camel.component.jsonvalidator.springboot.JsonValidatorComponentConverter diff --git a/tooling/camel-spring-boot-dependencies/pom.xml b/tooling/camel-spring-boot-dependencies/pom.xml index c1eed92a563..49a9a3c9d51 100644 --- a/tooling/camel-spring-boot-dependencies/pom.xml +++ b/tooling/camel-spring-boot-dependencies/pom.xml @@ -54,167 +54,167 @@ <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-all</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-alts</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-android</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-api</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-auth</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-benchmarks</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-binder</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-census</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-context</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-core</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-cronet</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-gcp-csm-observability</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-gcp-observability</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-googleapis</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-grpclb</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-inprocess</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-interop-testing</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty-shaded</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-okhttp</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-opentelemetry</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-protobuf</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-protobuf-lite</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-rls</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-services</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-servlet</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-servlet-jakarta</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-stub</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-testing</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-testing-proto</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-util</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-xds</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>protoc-gen-grpc-java</artifactId> - <version>1.65.0</version> + <version>1.65.1</version> <type>pom</type> </dependency> <dependency>