This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch df2 in repository https://gitbox.apache.org/repos/asf/camel.git
commit f323b178f19e667113f860bf07e8b64fa8409023 Author: Claus Ibsen <[email protected]> AuthorDate: Tue Aug 19 07:28:27 2025 +0200 CAMEL-22354: dataformats - Align all data formats getter setters to model --- .../camel/catalog/dataformats/snakeYaml.json | 2 +- .../apache/camel/catalog/models/typeFilter.json | 2 +- .../org/apache/camel/catalog/models/yaml.json | 2 +- .../apache/camel/catalog/schemas/camel-spring.xsd | 2 +- .../apache/camel/catalog/schemas/camel-xml-io.xsd | 2 +- .../snakeyaml/SnakeYAMLDataFormatConfigurer.java | 24 ++-- .../camel/component/snakeyaml/snakeYaml.json | 2 +- .../component/snakeyaml/SnakeYAMLDataFormat.java | 130 ++++++--------------- .../apache/camel/model/dataformat/typeFilter.json | 2 +- .../org/apache/camel/model/dataformat/yaml.json | 2 +- .../camel/model/dataformat/YAMLDataFormat.java | 1 + .../model/dataformat/YAMLTypeFilterDefinition.java | 2 +- .../java/org/apache/camel/xml/out/ModelWriter.java | 2 +- .../org/apache/camel/yaml/out/ModelWriter.java | 2 +- .../dsl/yaml/deserializers/ModelDeserializers.java | 2 +- .../generated/resources/schema/camelYamlDsl.json | 4 +- 16 files changed, 66 insertions(+), 117 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/snakeYaml.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/snakeYaml.json index e6d110591fa..c031af73545 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/snakeYaml.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/snakeYaml.json @@ -26,7 +26,7 @@ "useApplicationContextClassLoader": { "index": 7, "kind": "attribute", "displayName": "Use Application Context Class Loader", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Use ApplicationContextClassLoader as custom ClassLoader" }, "prettyFlow": { "index": 8, "kind": "attribute", "displayName": "Pretty Flow", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Force the emitter to produce a pretty YAML document when using the flow style." }, "allowAnyType": { "index": 9, "kind": "attribute", "displayName": "Allow Any Type", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allow any class to be un-marshaled" }, - "typeFilter": { "index": 10, "kind": "element", "displayName": "Type Filter", "group": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.dataformat.YAMLTypeFilterDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Set the types SnakeYAML is allowed to un-marshall" }, + "typeFilter": { "index": 10, "kind": "element", "displayName": "Type Filter", "group": "advanced", "label": "advanced", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.dataformat.YAMLTypeFilterDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Set the types SnakeYAML is allowed to un-marshall" }, "maxAliasesForCollections": { "index": 11, "kind": "attribute", "displayName": "Max Aliases For Collections", "group": "advanced", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "50", "description": "Set the maximum amount of aliases allowed for collections." }, "allowRecursiveKeys": { "index": 12, "kind": "attribute", "displayName": "Allow Recursive Keys", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Set whether recursive keys are allowed." } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/typeFilter.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/typeFilter.json index 130fe40a77b..3a36986f468 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/typeFilter.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/typeFilter.json @@ -12,6 +12,6 @@ }, "properties": { "value": { "index": 0, "kind": "attribute", "displayName": "Value", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Value of type such as class name or regular expression" }, - "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": false, "type": "object", "javaType": "org.apache.camel.model.dataformat.YAMLTypeFilterType", "deprecated": false, "autowired": false, "secret": false, "description": "Whether to filter by class type or regular expression" } + "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": false, "type": "enum", "javaType": "org.apache.camel.model.dataformat.YAMLTypeFilterType", "enum": [ "type", "regexp" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "type", "description": "Whether to filter by class type or regular expression" } } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/yaml.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/yaml.json index 06e064ada2d..61b64870955 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/yaml.json +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/yaml.json @@ -23,7 +23,7 @@ "useApplicationContextClassLoader": { "index": 7, "kind": "attribute", "displayName": "Use Application Context Class Loader", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Use ApplicationContextClassLoader as custom ClassLoader" }, "prettyFlow": { "index": 8, "kind": "attribute", "displayName": "Pretty Flow", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Force the emitter to produce a pretty YAML document when using the flow style." }, "allowAnyType": { "index": 9, "kind": "attribute", "displayName": "Allow Any Type", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allow any class to be un-marshaled" }, - "typeFilter": { "index": 10, "kind": "element", "displayName": "Type Filter", "group": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.dataformat.YAMLTypeFilterDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Set the types SnakeYAML is allowed to un-marshall" }, + "typeFilter": { "index": 10, "kind": "element", "displayName": "Type Filter", "group": "advanced", "label": "advanced", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.dataformat.YAMLTypeFilterDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Set the types SnakeYAML is allowed to un-marshall" }, "maxAliasesForCollections": { "index": 11, "kind": "attribute", "displayName": "Max Aliases For Collections", "group": "advanced", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "50", "description": "Set the maximum amount of aliases allowed for collections." }, "allowRecursiveKeys": { "index": 12, "kind": "attribute", "displayName": "Allow Recursive Keys", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Set whether recursive keys are allowed." } } diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd index f5ef62935ff..b0b32c4f35e 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd @@ -10898,7 +10898,7 @@ Value of type such as class name or regular expression. <xs:annotation> <xs:documentation xml:lang="en"> <![CDATA[ -Whether to filter by class type or regular expression. +Whether to filter by class type or regular expression. Default value: type ]]> </xs:documentation> </xs:annotation> diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd index 0e73d9f4424..572e4963296 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd @@ -9571,7 +9571,7 @@ Value of type such as class name or regular expression. <xs:annotation> <xs:documentation xml:lang="en"> <![CDATA[ -Whether to filter by class type or regular expression. +Whether to filter by class type or regular expression. Default value: type ]]> </xs:documentation> </xs:annotation> diff --git a/components/camel-snakeyaml/src/generated/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormatConfigurer.java b/components/camel-snakeyaml/src/generated/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormatConfigurer.java index dd04f97f97e..64d296316b9 100644 --- a/components/camel-snakeyaml/src/generated/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormatConfigurer.java +++ b/components/camel-snakeyaml/src/generated/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormatConfigurer.java @@ -24,12 +24,12 @@ public class SnakeYAMLDataFormatConfigurer extends org.apache.camel.support.comp Map<String, Object> map = new CaseInsensitiveMap(); map.put("AllowAnyType", boolean.class); map.put("AllowRecursiveKeys", boolean.class); - map.put("Constructor", java.util.function.Function.class); - map.put("DumperOptions", java.util.function.Function.class); + map.put("Constructor", org.yaml.snakeyaml.constructor.BaseConstructor.class); + map.put("DumperOptions", org.yaml.snakeyaml.DumperOptions.class); map.put("MaxAliasesForCollections", int.class); map.put("PrettyFlow", boolean.class); - map.put("Representer", java.util.function.Function.class); - map.put("Resolver", java.util.function.Function.class); + map.put("Representer", org.yaml.snakeyaml.representer.Representer.class); + map.put("Resolver", org.yaml.snakeyaml.resolver.Resolver.class); map.put("UnmarshalType", java.lang.Class.class); map.put("UseApplicationContextClassLoader", boolean.class); ALL_OPTIONS = map; @@ -43,15 +43,15 @@ public class SnakeYAMLDataFormatConfigurer extends org.apache.camel.support.comp case "allowAnyType": target.setAllowAnyType(property(camelContext, boolean.class, value)); return true; case "allowrecursivekeys": case "allowRecursiveKeys": target.setAllowRecursiveKeys(property(camelContext, boolean.class, value)); return true; - case "constructor": target.setConstructor(property(camelContext, java.util.function.Function.class, value)); return true; + case "constructor": target.setConstructor(property(camelContext, org.yaml.snakeyaml.constructor.BaseConstructor.class, value)); return true; case "dumperoptions": - case "dumperOptions": target.setDumperOptions(property(camelContext, java.util.function.Function.class, value)); return true; + case "dumperOptions": target.setDumperOptions(property(camelContext, org.yaml.snakeyaml.DumperOptions.class, value)); return true; case "maxaliasesforcollections": case "maxAliasesForCollections": target.setMaxAliasesForCollections(property(camelContext, int.class, value)); return true; case "prettyflow": case "prettyFlow": target.setPrettyFlow(property(camelContext, boolean.class, value)); return true; - case "representer": target.setRepresenter(property(camelContext, java.util.function.Function.class, value)); return true; - case "resolver": target.setResolver(property(camelContext, java.util.function.Function.class, value)); return true; + case "representer": target.setRepresenter(property(camelContext, org.yaml.snakeyaml.representer.Representer.class, value)); return true; + case "resolver": target.setResolver(property(camelContext, org.yaml.snakeyaml.resolver.Resolver.class, value)); return true; case "unmarshaltype": case "unmarshalType": target.setUnmarshalType(property(camelContext, java.lang.Class.class, value)); return true; case "useapplicationcontextclassloader": @@ -72,15 +72,15 @@ public class SnakeYAMLDataFormatConfigurer extends org.apache.camel.support.comp case "allowAnyType": return boolean.class; case "allowrecursivekeys": case "allowRecursiveKeys": return boolean.class; - case "constructor": return java.util.function.Function.class; + case "constructor": return org.yaml.snakeyaml.constructor.BaseConstructor.class; case "dumperoptions": - case "dumperOptions": return java.util.function.Function.class; + case "dumperOptions": return org.yaml.snakeyaml.DumperOptions.class; case "maxaliasesforcollections": case "maxAliasesForCollections": return int.class; case "prettyflow": case "prettyFlow": return boolean.class; - case "representer": return java.util.function.Function.class; - case "resolver": return java.util.function.Function.class; + case "representer": return org.yaml.snakeyaml.representer.Representer.class; + case "resolver": return org.yaml.snakeyaml.resolver.Resolver.class; case "unmarshaltype": case "unmarshalType": return java.lang.Class.class; case "useapplicationcontextclassloader": diff --git a/components/camel-snakeyaml/src/generated/resources/META-INF/org/apache/camel/component/snakeyaml/snakeYaml.json b/components/camel-snakeyaml/src/generated/resources/META-INF/org/apache/camel/component/snakeyaml/snakeYaml.json index e6d110591fa..c031af73545 100644 --- a/components/camel-snakeyaml/src/generated/resources/META-INF/org/apache/camel/component/snakeyaml/snakeYaml.json +++ b/components/camel-snakeyaml/src/generated/resources/META-INF/org/apache/camel/component/snakeyaml/snakeYaml.json @@ -26,7 +26,7 @@ "useApplicationContextClassLoader": { "index": 7, "kind": "attribute", "displayName": "Use Application Context Class Loader", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Use ApplicationContextClassLoader as custom ClassLoader" }, "prettyFlow": { "index": 8, "kind": "attribute", "displayName": "Pretty Flow", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Force the emitter to produce a pretty YAML document when using the flow style." }, "allowAnyType": { "index": 9, "kind": "attribute", "displayName": "Allow Any Type", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allow any class to be un-marshaled" }, - "typeFilter": { "index": 10, "kind": "element", "displayName": "Type Filter", "group": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.dataformat.YAMLTypeFilterDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Set the types SnakeYAML is allowed to un-marshall" }, + "typeFilter": { "index": 10, "kind": "element", "displayName": "Type Filter", "group": "advanced", "label": "advanced", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.dataformat.YAMLTypeFilterDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Set the types SnakeYAML is allowed to un-marshall" }, "maxAliasesForCollections": { "index": 11, "kind": "attribute", "displayName": "Max Aliases For Collections", "group": "advanced", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "50", "description": "Set the maximum amount of aliases allowed for collections." }, "allowRecursiveKeys": { "index": 12, "kind": "attribute", "displayName": "Allow Recursive Keys", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Set whether recursive keys are allowed." } } diff --git a/components/camel-snakeyaml/src/main/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormat.java b/components/camel-snakeyaml/src/main/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormat.java index 78e53dd8668..d16d6b61ad6 100644 --- a/components/camel-snakeyaml/src/main/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormat.java +++ b/components/camel-snakeyaml/src/main/java/org/apache/camel/component/snakeyaml/SnakeYAMLDataFormat.java @@ -30,7 +30,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.function.Function; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; @@ -61,10 +60,10 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor private CamelContext camelContext; private final ThreadLocal<WeakReference<Yaml>> yamlCache; - private Function<CamelContext, BaseConstructor> constructor; - private Function<CamelContext, Representer> representer; - private Function<CamelContext, DumperOptions> dumperOptions; - private Function<CamelContext, Resolver> resolver; + private BaseConstructor constructor; + private Representer representer; + private DumperOptions dumperOptions; + private Resolver resolver; private ClassLoader classLoader; private String unmarshalTypeName; private Class<?> unmarshalType; @@ -83,16 +82,7 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor public SnakeYAMLDataFormat(Class<?> type) { this.yamlCache = new ThreadLocal<>(); - this.constructor = this::defaultConstructor; - this.representer = this::defaultRepresenter; - this.dumperOptions = this::defaultDumperOptions; - this.resolver = this::defaultResolver; - - if (type != null) { - this.unmarshalType = type; - this.typeFilters = new CopyOnWriteArrayList<>(); - this.typeFilters.add(TypeFilters.types(type)); - } + this.unmarshalType = type; } @Override @@ -113,7 +103,7 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor @Override public void marshal(final Exchange exchange, final Object graph, final OutputStream stream) throws Exception { try (OutputStreamWriter osw = new OutputStreamWriter(stream, ExchangeHelper.getCharsetName(exchange))) { - getYaml(exchange.getContext()).dump(graph, osw); + getYaml().dump(graph, osw); } } @@ -127,14 +117,14 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor Class<?> unmarshalObjectType = unmarshalType != null ? unmarshalType : Object.class; if (body instanceof String s) { - return getYaml(exchange.getContext()).loadAs(s, unmarshalObjectType); + return getYaml().loadAs(s, unmarshalObjectType); } else if (body instanceof Reader r) { - return getYaml(exchange.getContext()).loadAs(r, unmarshalObjectType); + return getYaml().loadAs(r, unmarshalObjectType); } else { // fallback to InputStream InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, exchange, body); Reader r = new InputStreamReader(is, ExchangeHelper.getCharsetName(exchange)); - return getYaml(exchange.getContext()).loadAs(r, unmarshalObjectType); + return getYaml().loadAs(r, unmarshalObjectType); } } @@ -145,9 +135,25 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor if (unmarshalTypeName != null && unmarshalType == null) { setUnmarshalType(camelContext.getClassResolver().resolveClass(unmarshalTypeName)); } + if (this.constructor == null) { + this.constructor = defaultConstructor(camelContext); + } + if (this.representer == null) { + this.representer = defaultRepresenter(); + } + if (this.dumperOptions == null) { + this.dumperOptions = defaultDumperOptions(); + } + if (this.resolver == null) { + this.resolver = defaultResolver(); + } + if (unmarshalType != null) { + this.typeFilters = new CopyOnWriteArrayList<>(); + this.typeFilters.add(TypeFilters.types(unmarshalType)); + } } - protected Yaml getYaml(CamelContext context) { + protected Yaml getYaml() { Yaml yaml = null; WeakReference<Yaml> ref = yamlCache.get(); @@ -160,61 +166,42 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor options.setTagInspector(new TrustedTagInspector()); options.setAllowRecursiveKeys(allowRecursiveKeys); options.setMaxAliasesForCollections(maxAliasesForCollections); - - yaml = new Yaml( - this.constructor.apply(context), - this.representer.apply(context), - this.dumperOptions.apply(context), - options, - this.resolver.apply(context)); - + yaml = new Yaml(constructor, representer, dumperOptions, options, resolver); yamlCache.set(new WeakReference<>(yaml)); } return yaml; } - public Function<CamelContext, BaseConstructor> getConstructor() { + public BaseConstructor getConstructor() { return constructor; } - /** - * BaseConstructor to construct incoming documents. - */ - public void setConstructor(Function<CamelContext, BaseConstructor> constructor) { + public void setConstructor(BaseConstructor constructor) { this.constructor = constructor; } - public Function<CamelContext, Representer> getRepresenter() { + public Representer getRepresenter() { return representer; } - /** - * Representer to emit outgoing objects. - */ - public void setRepresenter(Function<CamelContext, Representer> representer) { + public void setRepresenter(Representer representer) { this.representer = representer; } - public Function<CamelContext, DumperOptions> getDumperOptions() { + public DumperOptions getDumperOptions() { return dumperOptions; } - /** - * DumperOptions to configure outgoing objects. - */ - public void setDumperOptions(Function<CamelContext, DumperOptions> dumperOptions) { + public void setDumperOptions(DumperOptions dumperOptions) { this.dumperOptions = dumperOptions; } - public Function<CamelContext, Resolver> getResolver() { + public Resolver getResolver() { return resolver; } - /** - * Resolver to detect implicit type - */ - public void setResolver(Function<CamelContext, Resolver> resolver) { + public void setResolver(Resolver resolver) { this.resolver = resolver; } @@ -222,9 +209,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor return classLoader; } - /** - * Set a custom classloader - */ public void setClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } @@ -241,9 +225,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor return this.unmarshalType; } - /** - * Class of the object to be created - */ public void setUnmarshalType(Class<?> unmarshalType) { this.unmarshalType = unmarshalType; addTypeFilters(TypeFilters.types(unmarshalType)); @@ -253,9 +234,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor return typeDescriptions; } - /** - * Make YAML aware how to parse a custom Class. - */ public void setTypeDescriptions(List<TypeDescription> typeDescriptions) { this.typeDescriptions = new CopyOnWriteArrayList<>(typeDescriptions); } @@ -264,7 +242,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor if (this.typeDescriptions == null) { this.typeDescriptions = new CopyOnWriteArrayList<>(); } - this.typeDescriptions.addAll(typeDescriptions); } @@ -276,7 +253,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor if (this.typeDescriptions == null) { this.typeDescriptions = new CopyOnWriteArrayList<>(); } - this.typeDescriptions.add(new TypeDescription(type, tag)); } @@ -284,9 +260,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor return classTags; } - /** - * Define a tag for the <code>Class</code> to serialize. - */ public void setClassTags(Map<Class<?>, Tag> classTags) { this.classTags = new ConcurrentHashMap<>(); this.classTags.putAll(classTags); @@ -296,7 +269,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor if (this.classTags == null) { this.classTags = new ConcurrentHashMap<>(); } - this.classTags.put(type, tag); } @@ -304,9 +276,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor return useApplicationContextClassLoader; } - /** - * Use ApplicationContextClassLoader as custom ClassLoader - */ public void setUseApplicationContextClassLoader(boolean useApplicationContextClassLoader) { this.useApplicationContextClassLoader = useApplicationContextClassLoader; } @@ -315,16 +284,10 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor return prettyFlow; } - /** - * Force the emitter to produce a pretty YAML document when using the flow style. - */ public void setPrettyFlow(boolean prettyFlow) { this.prettyFlow = prettyFlow; } - /** - * Convenience method to set class tag for bot <code>Constructor</code> and <code>Representer</code> - */ public void addTag(Class<?> type, Tag tag) { addClassTags(type, tag); addTypeDescription(type, tag); @@ -334,16 +297,12 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor return typeFilters; } - /** - * Set the types SnakeYAML is allowed to un-marshall - */ public void setTypeFilters(List<TypeFilter> typeFilters) { this.typeFilters = new CopyOnWriteArrayList<>(typeFilters); } public void setTypeFilterDefinitions(List<String> typeFilterDefinitions) { this.typeFilters = new CopyOnWriteArrayList<>(); - for (String definition : typeFilterDefinitions) { TypeFilters.valueOf(definition).ifPresent(this.typeFilters::add); } @@ -353,7 +312,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor if (this.typeFilters == null) { this.typeFilters = new CopyOnWriteArrayList<>(); } - this.typeFilters.addAll(typeFilters); } @@ -365,9 +323,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor return allowAnyType; } - /** - * Allow any class to be un-marshaled, same as setTypeFilters(TypeFilters.allowAll()) - */ public void setAllowAnyType(boolean allowAnyType) { this.allowAnyType = allowAnyType; } @@ -376,9 +331,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor return maxAliasesForCollections; } - /** - * Set the maximum amount of aliases allowed for collections. - */ public void setMaxAliasesForCollections(int maxAliasesForCollections) { this.maxAliasesForCollections = maxAliasesForCollections; } @@ -387,9 +339,6 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor return allowRecursiveKeys; } - /** - * Set whether recursive keys are allowed. - */ public void setAllowRecursiveKeys(boolean allowRecursiveKeys) { this.allowRecursiveKeys = allowRecursiveKeys; } @@ -432,26 +381,23 @@ public final class SnakeYAMLDataFormat extends ServiceSupport implements DataFor return yamlConstructor; } - private Representer defaultRepresenter(CamelContext context) { + private Representer defaultRepresenter() { Representer yamlRepresenter = new Representer(new DumperOptions()); - if (classTags != null) { for (Map.Entry<Class<?>, Tag> entry : classTags.entrySet()) { yamlRepresenter.addClassTag(entry.getKey(), entry.getValue()); } } - return yamlRepresenter; } - private DumperOptions defaultDumperOptions(CamelContext context) { + private DumperOptions defaultDumperOptions() { DumperOptions yamlDumperOptions = new DumperOptions(); yamlDumperOptions.setPrettyFlow(prettyFlow); - return yamlDumperOptions; } - private Resolver defaultResolver(CamelContext context) { + private Resolver defaultResolver() { return new Resolver(); } diff --git a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/typeFilter.json b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/typeFilter.json index 130fe40a77b..3a36986f468 100644 --- a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/typeFilter.json +++ b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/typeFilter.json @@ -12,6 +12,6 @@ }, "properties": { "value": { "index": 0, "kind": "attribute", "displayName": "Value", "group": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Value of type such as class name or regular expression" }, - "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": false, "type": "object", "javaType": "org.apache.camel.model.dataformat.YAMLTypeFilterType", "deprecated": false, "autowired": false, "secret": false, "description": "Whether to filter by class type or regular expression" } + "type": { "index": 1, "kind": "attribute", "displayName": "Type", "group": "common", "required": false, "type": "enum", "javaType": "org.apache.camel.model.dataformat.YAMLTypeFilterType", "enum": [ "type", "regexp" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "type", "description": "Whether to filter by class type or regular expression" } } } diff --git a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/yaml.json b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/yaml.json index 06e064ada2d..61b64870955 100644 --- a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/yaml.json +++ b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/yaml.json @@ -23,7 +23,7 @@ "useApplicationContextClassLoader": { "index": 7, "kind": "attribute", "displayName": "Use Application Context Class Loader", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Use ApplicationContextClassLoader as custom ClassLoader" }, "prettyFlow": { "index": 8, "kind": "attribute", "displayName": "Pretty Flow", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Force the emitter to produce a pretty YAML document when using the flow style." }, "allowAnyType": { "index": 9, "kind": "attribute", "displayName": "Allow Any Type", "group": "common", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allow any class to be un-marshaled" }, - "typeFilter": { "index": 10, "kind": "element", "displayName": "Type Filter", "group": "common", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.dataformat.YAMLTypeFilterDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Set the types SnakeYAML is allowed to un-marshall" }, + "typeFilter": { "index": 10, "kind": "element", "displayName": "Type Filter", "group": "advanced", "label": "advanced", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.dataformat.YAMLTypeFilterDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Set the types SnakeYAML is allowed to un-marshall" }, "maxAliasesForCollections": { "index": 11, "kind": "attribute", "displayName": "Max Aliases For Collections", "group": "advanced", "label": "advanced", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "50", "description": "Set the maximum amount of aliases allowed for collections." }, "allowRecursiveKeys": { "index": 12, "kind": "attribute", "displayName": "Allow Recursive Keys", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Set whether recursive keys are allowed." } } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLDataFormat.java b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLDataFormat.java index 83b7cd954b0..1b545e0af15 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLDataFormat.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLDataFormat.java @@ -69,6 +69,7 @@ public class YAMLDataFormat extends DataFormatDefinition { @Metadata(javaType = "java.lang.Boolean") private String allowAnyType; @XmlElement(name = "typeFilter") + @Metadata(label = "advanced") private List<YAMLTypeFilterDefinition> typeFilters; @XmlAttribute @Metadata(label = "advanced", javaType = "java.lang.Integer", defaultValue = "50") diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLTypeFilterDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLTypeFilterDefinition.java index 9792066ca5a..336f26f1934 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLTypeFilterDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/YAMLTypeFilterDefinition.java @@ -32,7 +32,7 @@ public class YAMLTypeFilterDefinition implements CopyableDefinition<YAMLTypeFilt @XmlAttribute private String value; @XmlAttribute - @Metadata(javaType = "org.apache.camel.model.dataformat.YAMLTypeFilterType") + @Metadata(javaType = "org.apache.camel.model.dataformat.YAMLTypeFilterType", enums = "type,regexp", defaultValue = "type") private String type; public YAMLTypeFilterDefinition() { diff --git a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java index d5d6af2d4e7..2a4780ee420 100644 --- a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java +++ b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java @@ -2976,7 +2976,7 @@ public class ModelWriter extends BaseWriter { } protected void doWriteYAMLTypeFilterDefinition(String name, YAMLTypeFilterDefinition def) throws IOException { startElement(name); - doWriteAttribute("type", def.getType(), null); + doWriteAttribute("type", def.getType(), "type"); doWriteAttribute("value", def.getValue(), null); endElement(name); } diff --git a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java index b8d269c34a3..23c2d11124d 100644 --- a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java +++ b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java @@ -2976,7 +2976,7 @@ public class ModelWriter extends BaseWriter { } protected void doWriteYAMLTypeFilterDefinition(String name, YAMLTypeFilterDefinition def) throws IOException { startElement(name); - doWriteAttribute("type", def.getType(), null); + doWriteAttribute("type", def.getType(), "type"); doWriteAttribute("value", def.getValue(), null); endElement(name); } diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java index 5022a7c0bab..2515627a598 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java @@ -21337,7 +21337,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { displayName = "YAML Type Filter", deprecated = false, properties = { - @YamlProperty(name = "type", type = "string", description = "Whether to filter by class type or regular expression", displayName = "Type"), + @YamlProperty(name = "type", type = "enum:type,regexp", defaultValue = "type", description = "Whether to filter by class type or regular expression", displayName = "Type"), @YamlProperty(name = "value", type = "string", description = "Value of type such as class name or regular expression", displayName = "Value") } ) diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json index 71362df4ad3..493cf5506bb 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json @@ -12553,7 +12553,9 @@ "type" : { "type" : "string", "title" : "Type", - "description" : "Whether to filter by class type or regular expression" + "description" : "Whether to filter by class type or regular expression", + "default" : "type", + "enum" : [ "type", "regexp" ] }, "value" : { "type" : "string",
