@@ -2851,6 +2851,44 @@ void projectShouldReadNestedProjection() {
2851
2851
assertThat (person .getAddresses ()).extracting (AddressProjection ::getStreet ).hasSize (1 ).containsOnly ("hwy" );
2852
2852
}
2853
2853
2854
+ @ Test // GH-4609
2855
+ void projectShouldReadNestedInterfaceProjection () {
2856
+
2857
+ org .bson .Document source = new org .bson .Document ("foo" , "spring" ).append ("address" ,
2858
+ new org .bson .Document ("s" , "data" ).append ("city" , "mongodb" ));
2859
+
2860
+ EntityProjectionIntrospector introspector = EntityProjectionIntrospector .create (converter .getProjectionFactory (),
2861
+ EntityProjectionIntrospector .ProjectionPredicate .typeHierarchy ()
2862
+ .and ((target , underlyingType ) -> !converter .conversions .isSimpleType (target )),
2863
+ mappingContext );
2864
+
2865
+ EntityProjection <WithNestedInterfaceProjection , Person > projection = introspector .introspect (WithNestedInterfaceProjection .class ,
2866
+ Person .class );
2867
+ WithNestedInterfaceProjection person = converter .project (projection , source );
2868
+
2869
+ assertThat (person .getFirstname ()).isEqualTo ("spring" );
2870
+ assertThat (person .getAddress ().getStreet ()).isEqualTo ("data" );
2871
+ }
2872
+
2873
+ @ Test // GH-4609
2874
+ void projectShouldReadNestedDtoProjection () {
2875
+
2876
+ org .bson .Document source = new org .bson .Document ("foo" , "spring" ).append ("address" ,
2877
+ new org .bson .Document ("s" , "data" ).append ("city" , "mongodb" ));
2878
+
2879
+ EntityProjectionIntrospector introspector = EntityProjectionIntrospector .create (converter .getProjectionFactory (),
2880
+ EntityProjectionIntrospector .ProjectionPredicate .typeHierarchy ()
2881
+ .and ((target , underlyingType ) -> !converter .conversions .isSimpleType (target )),
2882
+ mappingContext );
2883
+
2884
+ EntityProjection <WithNestedDtoProjection , Person > projection = introspector .introspect (WithNestedDtoProjection .class ,
2885
+ Person .class );
2886
+ WithNestedDtoProjection person = converter .project (projection , source );
2887
+
2888
+ assertThat (person .getFirstname ()).isEqualTo ("spring" );
2889
+ assertThat (person .getAddress ().getStreet ()).isEqualTo ("data" );
2890
+ }
2891
+
2854
2892
@ Test // GH-2860
2855
2893
void projectShouldReadProjectionWithNestedEntity () {
2856
2894
@@ -3206,6 +3244,7 @@ static class Person implements Contact {
3206
3244
String lastname ;
3207
3245
3208
3246
Set <Address > addresses ;
3247
+ Address address ;
3209
3248
3210
3249
Person () {
3211
3250
@@ -3248,6 +3287,16 @@ interface WithNestedProjection {
3248
3287
Set <AddressProjection > getAddresses ();
3249
3288
}
3250
3289
3290
+ interface WithNestedInterfaceProjection {
3291
+ String getFirstname ();
3292
+ AddressProjection getAddress ();
3293
+ }
3294
+
3295
+ interface WithNestedDtoProjection {
3296
+ String getFirstname ();
3297
+ AddressDto getAddress ();
3298
+ }
3299
+
3251
3300
interface ProjectionWithNestedEntity {
3252
3301
3253
3302
Set <Address > getAddresses ();
@@ -3258,6 +3307,19 @@ interface AddressProjection {
3258
3307
String getStreet ();
3259
3308
}
3260
3309
3310
+ class AddressDto {
3311
+
3312
+ String street ;
3313
+
3314
+ public String getStreet () {
3315
+ return street ;
3316
+ }
3317
+
3318
+ public void setStreet (String street ) {
3319
+ this .street = street ;
3320
+ }
3321
+ }
3322
+
3261
3323
static class PersonDto {
3262
3324
3263
3325
LocalDate birthDate ;
0 commit comments