Skip to content

Commit b606387

Browse files
christophstroblmp911de
authored andcommitted
Add test to verify map keys retain order when mapped.
See: #4577 Original pull request: #4568
1 parent 785eabf commit b606387

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java

+15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.List;
2929
import java.util.Map;
3030
import java.util.Optional;
31+
import java.util.TreeMap;
3132

3233
import org.bson.conversions.Bson;
3334
import org.bson.types.Code;
@@ -1509,6 +1510,20 @@ void convertsListOfValuesForPropertyThatHasValueConverterButIsNotCollectionLikeO
15091510
assertThat(mappedObject).isEqualTo("{ 'text' : { $in : ['gnirps', 'atad'] } }");
15101511
}
15111512

1513+
@Test // GH-4577
1514+
void mappingShouldRetainMapKeyOrder() {
1515+
1516+
TreeMap<String, String> sourceMap = new TreeMap<>(Map.of("test1", "123", "test2", "456"));
1517+
1518+
org.bson.Document target = mapper.getMappedObject(query(where("simpleMap").is(sourceMap)).getQueryObject(),
1519+
context.getPersistentEntity(WithSimpleMap.class));
1520+
assertThat(target.get("simpleMap", Map.class)).containsExactlyEntriesOf(sourceMap);
1521+
}
1522+
1523+
class WithSimpleMap {
1524+
Map<String, String> simpleMap;
1525+
}
1526+
15121527
class WithDeepArrayNesting {
15131528

15141529
List<WithNestedArray> level0;

0 commit comments

Comments
 (0)