@@ -14,34 +14,12 @@ Every library requires adding the special camel component (see
14
14
"Dependency... " paragraphs further down). By default Camel uses the
15
15
SnakeYAML library.
16
16
17
- [[YAMLDataFormat-UsingYAMLdataformatwiththeSnakeYAMLlibrary]]
18
- Using YAML data format with the SnakeYAML library
19
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20
-
21
- [source,java]
22
- ------------------------------------------------------------
23
- // lets turn Object messages into yaml then send to MQSeries
24
- from("activemq:My.Queue")
25
- .marshal().yaml()
26
- .to("mqseries:Another.Queue");
27
- ------------------------------------------------------------
28
-
29
- [source,java]
30
- ------------------------------------------------------------
31
- // lets turn Object messages into yaml then send to MQSeries
32
- from("activemq:My.Queue")
33
- .marshal().yaml(YAMLLibrary.SnakeYAML)
34
- .to("mqseries:Another.Queue");
35
- ------------------------------------------------------------
36
-
37
17
[[YAML-Options]]
38
18
YAML Options
39
19
^^^^^^^^^^^^
40
20
41
-
42
-
43
21
// dataformat options: START
44
- The YAML SnakeYAML dataformat supports 8 options which are listed below.
22
+ The YAML SnakeYAML dataformat supports 10 options which are listed below.
45
23
46
24
47
25
@@ -57,11 +35,48 @@ The YAML SnakeYAML dataformat supports 8 options which are listed below.
57
35
| resolver | | String | Resolver to detect implicit type
58
36
| useApplicationContextClassLoader | true | Boolean | Use ApplicationContextClassLoader as custom ClassLoader
59
37
| prettyFlow | false | Boolean | Force the emitter to produce a pretty YAML document when using the flow style.
38
+ | allowAnyType | false | Boolean | Allow any class to be un-marshaled
39
+ | typeFilter | | List | Set the types SnakeYAML is allowed to un-marshall
60
40
|=======================================================================
61
41
{% endraw %}
62
42
// dataformat options: END
63
43
44
+ WARNING: SnakeYAML can load any class from YAML definition which may lead to security breach so by default, SnakeYAML DataForma restrict the object it can load to standard Java objects like List or Long. If you want to load custom POJOs you need to add theirs type to SnakeYAML DataFormat type filter list. If your source is trusted, you can set the property allowAnyType to true so SnakeYAML DataForma won't perform any filter on the types.
64
45
46
+ [[YAMLDataFormat-UsingYAMLdataformatwiththeSnakeYAMLlibrary]]
47
+ Using YAML data format with the SnakeYAML library
48
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49
+
50
+ - Turn Object messages into yaml then send to MQSeries
51
+ +
52
+ [source,java]
53
+ ------------------------------------------------------------
54
+ from("activemq:My.Queue")
55
+ .marshal().yaml()
56
+ .to("mqseries:Another.Queue");
57
+ ------------------------------------------------------------
58
+ +
59
+ [source,java]
60
+ ------------------------------------------------------------
61
+ from("activemq:My.Queue")
62
+ .marshal().yaml(YAMLLibrary.SnakeYAML)
63
+ .to("mqseries:Another.Queue");
64
+ ------------------------------------------------------------
65
+
66
+ - Restrict classes to be loaded from YAML
67
+ +
68
+ [source,java]
69
+ ------------------------------------------------------------
70
+ // Creat a SnakeYAMLDataFormat instance
71
+ SnakeYAMLDataFormat yaml = new SnakeYAMLDataFormat();
72
+
73
+ // Restrict classes to be loaded from YAML
74
+ yaml.addTypeFilters(TypeFilters.types(MyPojo.class, MyOtherPojo.class));
75
+
76
+ from("activemq:My.Queue")
77
+ .unmarshal(yaml)
78
+ .to("mqseries:Another.Queue");
79
+ ------------------------------------------------------------
65
80
66
81
[[YAMLDataFormat-UsingYAMLinSpringDSL]]
67
82
Using YAML in Spring DSL
@@ -72,56 +87,50 @@ declare the data formats first. This is done in the *DataFormats* XML
72
87
tag.
73
88
74
89
[source,xml]
75
- ----------------------------------------------------------------------------------------------------------------------------------
76
- <dataFormats>
77
- <!-- here we define a YAML data format with the id snak and that it should use the TestPojo as the class type when
78
- doing unmarshal. The unmarshalTypeName is optional, if not provided Camel will use a Object.class as the type -->
79
- <yaml id="snake" library="SnakeYAML" unmarshalTypeName="org.apache.camel.component.yaml.model.TestPojo"/>
80
- </dataFormats>
81
- ----------------------------------------------------------------------------------------------------------------------------------
82
-
83
- And then you can refer to this id in the route:
90
+ --------------------------------------------------------------------------------
91
+ <dataFormats>
92
+ <!--
93
+ here we define a YAML data format with the id snake and that it should use
94
+ the TestPojo as the class type when doing unmarshal. The unmarshalTypeName
95
+ is optional
96
+ -->
97
+ <yaml
98
+ id="snake"
99
+ library="SnakeYAML"
100
+ unmarshalTypeName="org.apache.camel.component.yaml.model.TestPojo"/>
101
+
102
+ <!--
103
+ here we define a YAML data format with the id snake-safe which restricts the
104
+ classes to be loaded from YAML to TestPojo and those belonging to package
105
+ com.mycompany
106
+ -->
107
+ <yaml id="snake-safe">
108
+ <typeFilter value="org.apache.camel.component.yaml.model.TestPojo"/>
109
+ <typeFilter value="com.mycompany\..*" type="regexp"/>
110
+ </yaml>
111
+ </dataFormats>
112
+ --------------------------------------------------------------------------------
113
+
114
+ And then you can refer to those ids in the route:
84
115
85
116
[source,xml]
86
117
-------------------------------------
87
- <route>
88
- <from uri="direct:back"/>
89
- <unmarshal ref="snake"/>
90
- <to uri="mock:reverse"/>
91
- </route>
118
+ <route>
119
+ <from uri="direct:unmarshal"/>
120
+ <unmarshal>
121
+ <custom ref="snake"/>
122
+ </unmarshal>
123
+ <to uri="mock:unmarshal"/>
124
+ </route>
125
+ <route>
126
+ <from uri="direct:unmarshal-safe"/>
127
+ <unmarshal>
128
+ <custom ref="snake-safe"/>
129
+ </unmarshal>
130
+ <to uri="mock:unmarshal-safe"/>
131
+ </route>
92
132
-------------------------------------
93
133
94
-
95
-
96
- [[YAMLDataFormat-OptionsforSnakeYAMLDataFormat]]
97
- Options for SnakeYAML Data Format
98
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99
-
100
- [width="100%",cols="<25%,<25%,<25%,<25%",options="header",]
101
- |=======================================================================
102
- |Name |Type |Default |Description
103
- |unmarshalType |`Class` |`Object.class` |Class of the object to be created
104
-
105
- |classLoader |ClassLoader |null |The classloader to use to
106
- instantiate objects
107
-
108
- |constructor |String |null |A reference to an
109
- org.yaml.snakeyaml.constructor.BaseConstructor instance in the registry
110
-
111
- |representer |String |null |A reference to an
112
- org.yaml.snakeyaml.representer.Representer instance in the registry
113
-
114
- |dumperOptions |String |null |A reference to an
115
- org.yaml.snakeyaml.DumperOptions instance in the registry
116
-
117
- |resolver |String |null |A reference to an
118
- org.yaml.snakeyaml.resolver.Resolver instance in the registry
119
-
120
- |useApplicationContextClassLoader | Boolean |true |To use CamelContext's ApplicationContextClassLoader if no custom class loader is set and
121
- ApplicationContextClassLoader is provided
122
-
123
- |prettyFlow | Boolean |false |Force the emitter to produce a pretty YAML document when using the flow style
124
- |=======================================================================
125
134
126
135
[[YAMLDataFormat-DependenciesforSnakeYAML]]
127
136
Dependencies for SnakeYAML
0 commit comments