Skip to content

Commit 3c8a974

Browse files
committed
Merge branch '2.3.x' into 2.4.x
Closes gh-25176
2 parents 9da3b65 + b6d2da0 commit 3c8a974

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

buildSrc/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies {
2323
implementation("org.gradle:test-retry-gradle-plugin:1.1.9")
2424
implementation("org.springframework:spring-core:5.2.2.RELEASE")
2525
implementation("org.springframework:spring-web:5.2.2.RELEASE")
26-
implementation("com.google.code.gson:gson:2.8.5")
26+
implementation("com.fasterxml.jackson.core:jackson-databind:2.11.4")
2727
implementation("io.spring.javaformat:spring-javaformat-gradle-plugin:${javaFormatVersion}")
2828
testImplementation("org.assertj:assertj-core:3.11.1")
2929
testImplementation("org.apache.logging.log4j:log4j-core:2.12.1")

buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationProperties.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,17 +20,13 @@
2020
import java.io.FileReader;
2121
import java.io.IOException;
2222
import java.io.Reader;
23-
import java.lang.reflect.Type;
2423
import java.util.ArrayList;
2524
import java.util.List;
2625
import java.util.Map;
2726
import java.util.function.Function;
2827
import java.util.stream.Collectors;
2928

30-
import com.google.gson.Gson;
31-
import com.google.gson.GsonBuilder;
32-
import com.google.gson.reflect.TypeToken;
33-
import org.gradle.api.file.FileCollection;
29+
import com.fasterxml.jackson.databind.ObjectMapper;
3430

3531
/**
3632
* Configuration properties read from one or more
@@ -40,20 +36,18 @@
4036
*/
4137
final class ConfigurationProperties {
4238

43-
private static final Type MAP_TYPE = new MapTypeToken().getType();
44-
4539
private ConfigurationProperties() {
4640

4741
}
4842

4943
@SuppressWarnings("unchecked")
50-
static Map<String, ConfigurationProperty> fromFiles(FileCollection files) {
44+
static Map<String, ConfigurationProperty> fromFiles(Iterable<File> files) {
5145
List<ConfigurationProperty> configurationProperties = new ArrayList<>();
5246
try {
53-
Gson gson = new GsonBuilder().create();
47+
ObjectMapper objectMapper = new ObjectMapper();
5448
for (File file : files) {
5549
try (Reader reader = new FileReader(file)) {
56-
Map<String, Object> json = gson.fromJson(reader, MAP_TYPE);
50+
Map<String, Object> json = objectMapper.readValue(file, Map.class);
5751
List<Map<String, Object>> properties = (List<Map<String, Object>>) json.get("properties");
5852
for (Map<String, Object> property : properties) {
5953
String name = (String) property.get("name");
@@ -74,8 +68,4 @@ static Map<String, ConfigurationProperty> fromFiles(FileCollection files) {
7468
}
7569
}
7670

77-
private static final class MapTypeToken extends TypeToken<Map<String, Object>> {
78-
79-
}
80-
8171
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2012-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.context.properties;
18+
19+
import java.io.File;
20+
import java.util.Arrays;
21+
import java.util.Map;
22+
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
/**
28+
* Tests for {@link ConfigurationProperties}
29+
*
30+
* @author Andy Wilkinson
31+
*/
32+
class ConfigurationPropertiesTests {
33+
34+
@Test
35+
void whenJsonHasAnIntegerDefaultValueThenItRemainsAnIntegerWhenRead() {
36+
Map<String, ConfigurationProperty> properties = ConfigurationProperties
37+
.fromFiles(Arrays.asList(new File("src/test/resources/spring-configuration-metadata.json")));
38+
assertThat(properties.get("example.counter").getDefaultValue()).isEqualTo(0);
39+
}
40+
41+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"properties": [
3+
{
4+
"name": "example.counter",
5+
"type": "java.lang.Integer",
6+
"defaultValue": 0
7+
}
8+
]
9+
}

0 commit comments

Comments
 (0)