From 86c988d6533d58f9c1beb5ff53e81d8fdf35a73e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 28 Feb 2023 09:39:43 +0000 Subject: [PATCH] Improve compatibility with SnakeYAML 2.0 Closes gh-34405 --- .../boot/env/OriginTrackedYamlLoader.java | 4 +-- ...lPropertySourceLoaderSnakeYaml20Tests.java | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderSnakeYaml20Tests.java diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java index 61672116db..a245581eb2 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,8 +77,8 @@ class OriginTrackedYamlLoader extends YamlProcessor { private Yaml createYaml(LoaderOptions loaderOptions) { BaseConstructor constructor = new OriginTrackingConstructor(loaderOptions); - Representer representer = new Representer(); DumperOptions dumperOptions = new DumperOptions(); + Representer representer = new Representer(dumperOptions); Resolver resolver = HAS_RESOLVER_LIMIT ? new NoTimestampResolverWithLimit() : new NoTimestampResolver(); return new Yaml(constructor, representer, dumperOptions, loaderOptions, resolver); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderSnakeYaml20Tests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderSnakeYaml20Tests.java new file mode 100644 index 0000000000..6844401765 --- /dev/null +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/env/YamlPropertySourceLoaderSnakeYaml20Tests.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-2023 the original author or authors. + * + * Licensed 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 + * + * https://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.springframework.boot.env; + +import org.springframework.boot.testsupport.classpath.ClassPathOverrides; + +/** + * Tests for {@link YamlPropertySourceLoader} with SnakeYAML 2.0. + * + * @author Andy Wilkinson + */ +@ClassPathOverrides("org.yaml:snakeyaml:2.0") +class YamlPropertySourceLoaderSnakeYaml20Tests extends YamlPropertySourceLoaderTests { + +}