YamlPropertiesFactoryBean consistently exposes String values
Issue: SPR-14737
(cherry picked from commit 74c6188)
This commit is contained in:
@@ -29,6 +29,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
@@ -40,12 +41,9 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* Factory for collections that is aware of Java 5, Java 6, and Spring
|
||||
* collection types.
|
||||
* Factory for collections that is aware of Java 5, Java 6, and Spring collection types.
|
||||
*
|
||||
* <p>Mainly for internal use within the framework.
|
||||
* <p>The goal of this class is to avoid runtime dependencies on a specific
|
||||
* Java version, while nevertheless using the best collection implementation
|
||||
* that is available at runtime.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Arjen Poutsma
|
||||
@@ -324,6 +322,23 @@ public abstract class CollectionFactory {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a variant of {@code java.util.Properties} that automatically adapts
|
||||
* non-String values to String representations on {@link Properties#getProperty}.
|
||||
* @return a new {@code Properties} instance
|
||||
* @since 4.3.4
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static Properties createStringAdaptingProperties() {
|
||||
return new Properties() {
|
||||
@Override
|
||||
public String getProperty(String key) {
|
||||
Object value = get(key);
|
||||
return (value != null ? value.toString() : null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast the given type to a subtype of {@link Enum}.
|
||||
* @param enumType the enum type, never {@code null}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -110,10 +110,10 @@ public abstract class CollectionUtils {
|
||||
if (props != null) {
|
||||
for (Enumeration<?> en = props.propertyNames(); en.hasMoreElements();) {
|
||||
String key = (String) en.nextElement();
|
||||
Object value = props.getProperty(key);
|
||||
Object value = props.get(key);
|
||||
if (value == null) {
|
||||
// Potentially a non-String value...
|
||||
value = props.get(key);
|
||||
// Allow for defaults fallback or potentially overridden accessor...
|
||||
value = props.getProperty(key);
|
||||
}
|
||||
map.put((K) key, (V) value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user