Preserve property ordering in SpringIterableConfigurationPropertySource
Fixes gh-21470
This commit is contained in:
parent
4f31c3bfca
commit
beb7cb4b81
|
@ -19,9 +19,9 @@ package org.springframework.boot.context.properties.source;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.ConcurrentModificationException;
|
import java.util.ConcurrentModificationException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -259,7 +259,7 @@ class SpringIterableConfigurationPropertySource extends SpringConfigurationPrope
|
||||||
}
|
}
|
||||||
|
|
||||||
private <K, V> Map<K, V> cloneOrCreate(Map<K, V> source, int size) {
|
private <K, V> Map<K, V> cloneOrCreate(Map<K, V> source, int size) {
|
||||||
return (source != null) ? new HashMap<>(source) : new HashMap<>(size);
|
return (source != null) ? new LinkedHashMap<>(source) : new LinkedHashMap<>(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addParents(Map<ConfigurationPropertyName, Set<ConfigurationPropertyName>> descendants,
|
private void addParents(Map<ConfigurationPropertyName, Set<ConfigurationPropertyName>> descendants,
|
||||||
|
|
|
@ -224,6 +224,20 @@ class SpringIterableConfigurationPropertySourceTests {
|
||||||
assertThat(adapter.stream()).hasSize(2);
|
assertThat(adapter.stream()).hasSize(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void orderOfUnderlyingSourceIsPreserved() {
|
||||||
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
|
map.put("test.map.alpha", "value1");
|
||||||
|
map.put("test.map.bravo", "value2");
|
||||||
|
map.put("test.map.charlie", "value3");
|
||||||
|
map.put("test.map.delta", "value4");
|
||||||
|
EnumerablePropertySource<?> source = new OriginTrackedMapPropertySource("test", map, true);
|
||||||
|
SpringIterableConfigurationPropertySource propertySource = new SpringIterableConfigurationPropertySource(source,
|
||||||
|
DefaultPropertyMapper.INSTANCE);
|
||||||
|
assertThat(propertySource.stream().map(ConfigurationPropertyName::toString)).containsExactly("test.map.alpha",
|
||||||
|
"test.map.bravo", "test.map.charlie", "test.map.delta");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link PropertySource} that's also an {@link OriginLookup}.
|
* Test {@link PropertySource} that's also an {@link OriginLookup}.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue