@@ -1191,6 +1191,72 @@ void projectOnUnwrappedValue() {
11911191 assertThat (document ).isEqualTo (new org .bson .Document ("stringValue" , 1 ));
11921192 }
11931193
1194+ @ Test // GH-3601
1195+ void resolvesFieldnameWithUnderscoresCorrectly () {
1196+
1197+ Query query = query (where ("fieldname_with_underscores" ).exists (true ));
1198+
1199+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1200+ context .getPersistentEntity (WithPropertyUsingUnderscoreInName .class ));
1201+
1202+ assertThat (document ).isEqualTo (new org .bson .Document ("fieldname_with_underscores" , new org .bson .Document ("$exists" , true )));
1203+ }
1204+
1205+ @ Test // GH-3601
1206+ void resolvesMappedFieldnameWithUnderscoresCorrectly () {
1207+
1208+ Query query = query (where ("renamed_fieldname_with_underscores" ).exists (true ));
1209+
1210+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1211+ context .getPersistentEntity (WithPropertyUsingUnderscoreInName .class ));
1212+
1213+ assertThat (document ).isEqualTo (new org .bson .Document ("renamed" , new org .bson .Document ("$exists" , true )));
1214+ }
1215+
1216+ @ Test // GH-3601
1217+ void resolvesSimpleNestedFieldnameWithUnderscoresCorrectly () {
1218+
1219+ Query query = query (where ("simple.fieldname_with_underscores" ).exists (true ));
1220+
1221+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1222+ context .getPersistentEntity (WrapperAroundWithPropertyUsingUnderscoreInName .class ));
1223+
1224+ assertThat (document ).isEqualTo (new org .bson .Document ("simple.fieldname_with_underscores" , new org .bson .Document ("$exists" , true )));
1225+ }
1226+
1227+ @ Test // GH-3601
1228+ void resolvesSimpleNestedMappedFieldnameWithUnderscoresCorrectly () {
1229+
1230+ Query query = query (where ("simple.renamed_fieldname_with_underscores" ).exists (true ));
1231+
1232+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1233+ context .getPersistentEntity (WrapperAroundWithPropertyUsingUnderscoreInName .class ));
1234+
1235+ assertThat (document ).isEqualTo (new org .bson .Document ("simple.renamed" , new org .bson .Document ("$exists" , true )));
1236+ }
1237+
1238+ @ Test // GH-3601
1239+ void resolvesFieldNameWithUnderscoreOnNestedFieldnameWithUnderscoresCorrectly () {
1240+
1241+ Query query = query (where ("double_underscore.fieldname_with_underscores" ).exists (true ));
1242+
1243+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1244+ context .getPersistentEntity (WrapperAroundWithPropertyUsingUnderscoreInName .class ));
1245+
1246+ assertThat (document ).isEqualTo (new org .bson .Document ("double_underscore.fieldname_with_underscores" , new org .bson .Document ("$exists" , true )));
1247+ }
1248+
1249+ @ Test // GH-3601
1250+ void resolvesFieldNameWithUnderscoreOnNestedMappedFieldnameWithUnderscoresCorrectly () {
1251+
1252+ Query query = query (where ("double_underscore.renamed_fieldname_with_underscores" ).exists (true ));
1253+
1254+ org .bson .Document document = mapper .getMappedObject (query .getQueryObject (),
1255+ context .getPersistentEntity (WrapperAroundWithPropertyUsingUnderscoreInName .class ));
1256+
1257+ assertThat (document ).isEqualTo (new org .bson .Document ("double_underscore.renamed" , new org .bson .Document ("$exists" , true )));
1258+ }
1259+
11941260 class WithDeepArrayNesting {
11951261
11961262 List <WithNestedArray > level0 ;
@@ -1408,4 +1474,17 @@ static class UnwrappableType {
14081474 String transientValue ;
14091475 }
14101476
1477+ static class WrapperAroundWithPropertyUsingUnderscoreInName {
1478+
1479+ WithPropertyUsingUnderscoreInName simple ;
1480+ WithPropertyUsingUnderscoreInName double_underscore ;
1481+ }
1482+
1483+ static class WithPropertyUsingUnderscoreInName {
1484+
1485+ String fieldname_with_underscores ;
1486+
1487+ @ Field ("renamed" )
1488+ String renamed_fieldname_with_underscores ;
1489+ }
14111490}
0 commit comments