|
29 | 29 | import org.slf4j.Logger;
|
30 | 30 | import org.slf4j.LoggerFactory;
|
31 | 31 | import org.yaml.snakeyaml.DumperOptions;
|
| 32 | +import org.yaml.snakeyaml.LoaderOptions; |
32 | 33 | import org.yaml.snakeyaml.TypeDescription;
|
33 | 34 | import org.yaml.snakeyaml.Yaml;
|
34 | 35 | import org.yaml.snakeyaml.constructor.Constructor;
|
@@ -252,19 +253,25 @@ Set<KafkaStream> parseFile() throws IOException {
|
252 | 253 | }
|
253 | 254 |
|
254 | 255 | private static Yaml initYamlParser() {
|
255 |
| - Representer representer = new Representer(); |
| 256 | + DumperOptions dumperOptions = new DumperOptions(); |
| 257 | + Representer representer = new Representer(dumperOptions); |
256 | 258 | representer.addClassTag(StreamMetadata.class, Tag.MAP);
|
257 | 259 | TypeDescription typeDescription = new TypeDescription(StreamMetadata.class);
|
258 | 260 | representer.addTypeDescription(typeDescription);
|
259 | 261 | representer.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
|
260 |
| - return new Yaml(new ListConstructor<>(StreamMetadata.class), representer); |
| 262 | + LoaderOptions loaderOptions = new LoaderOptions(); |
| 263 | + // Allow global tag for StreamMetadata |
| 264 | + loaderOptions.setTagInspector( |
| 265 | + tag -> tag.getClassName().equals(StreamMetadata.class.getName())); |
| 266 | + return new Yaml(new ListConstructor<>(StreamMetadata.class, loaderOptions), representer); |
261 | 267 | }
|
262 | 268 |
|
263 | 269 | /** A custom constructor is required to read yaml lists at the root. */
|
264 | 270 | private static class ListConstructor<T> extends Constructor {
|
265 | 271 | private final Class<T> clazz;
|
266 | 272 |
|
267 |
| - public ListConstructor(final Class<T> clazz) { |
| 273 | + public ListConstructor(final Class<T> clazz, final LoaderOptions loaderOptions) { |
| 274 | + super(loaderOptions); |
268 | 275 | this.clazz = clazz;
|
269 | 276 | }
|
270 | 277 |
|
|
0 commit comments