@@ -2709,6 +2709,44 @@ void projectShouldReadNestedProjection() {
2709
2709
assertThat (person .getAddresses ()).extracting (AddressProjection ::getStreet ).hasSize (1 ).containsOnly ("hwy" );
2710
2710
}
2711
2711
2712
+ @ Test // GH-4609
2713
+ void projectShouldReadNestedInterfaceProjection () {
2714
+
2715
+ org .bson .Document source = new org .bson .Document ("foo" , "spring" ).append ("address" ,
2716
+ new org .bson .Document ("s" , "data" ).append ("city" , "mongodb" ));
2717
+
2718
+ EntityProjectionIntrospector introspector = EntityProjectionIntrospector .create (converter .getProjectionFactory (),
2719
+ EntityProjectionIntrospector .ProjectionPredicate .typeHierarchy ()
2720
+ .and ((target , underlyingType ) -> !converter .conversions .isSimpleType (target )),
2721
+ mappingContext );
2722
+
2723
+ EntityProjection <WithNestedInterfaceProjection , Person > projection = introspector .introspect (WithNestedInterfaceProjection .class ,
2724
+ Person .class );
2725
+ WithNestedInterfaceProjection person = converter .project (projection , source );
2726
+
2727
+ assertThat (person .getFirstname ()).isEqualTo ("spring" );
2728
+ assertThat (person .getAddress ().getStreet ()).isEqualTo ("data" );
2729
+ }
2730
+
2731
+ @ Test // GH-4609
2732
+ void projectShouldReadNestedDtoProjection () {
2733
+
2734
+ org .bson .Document source = new org .bson .Document ("foo" , "spring" ).append ("address" ,
2735
+ new org .bson .Document ("s" , "data" ).append ("city" , "mongodb" ));
2736
+
2737
+ EntityProjectionIntrospector introspector = EntityProjectionIntrospector .create (converter .getProjectionFactory (),
2738
+ EntityProjectionIntrospector .ProjectionPredicate .typeHierarchy ()
2739
+ .and ((target , underlyingType ) -> !converter .conversions .isSimpleType (target )),
2740
+ mappingContext );
2741
+
2742
+ EntityProjection <WithNestedDtoProjection , Person > projection = introspector .introspect (WithNestedDtoProjection .class ,
2743
+ Person .class );
2744
+ WithNestedDtoProjection person = converter .project (projection , source );
2745
+
2746
+ assertThat (person .getFirstname ()).isEqualTo ("spring" );
2747
+ assertThat (person .getAddress ().getStreet ()).isEqualTo ("data" );
2748
+ }
2749
+
2712
2750
@ Test // GH-2860
2713
2751
void projectShouldReadProjectionWithNestedEntity () {
2714
2752
@@ -2958,6 +2996,7 @@ static class Person implements Contact {
2958
2996
String lastname ;
2959
2997
2960
2998
Set <Address > addresses ;
2999
+ Address address ;
2961
3000
2962
3001
Person () {
2963
3002
@@ -2981,6 +3020,16 @@ interface WithNestedProjection {
2981
3020
Set <AddressProjection > getAddresses ();
2982
3021
}
2983
3022
3023
+ interface WithNestedInterfaceProjection {
3024
+ String getFirstname ();
3025
+ AddressProjection getAddress ();
3026
+ }
3027
+
3028
+ interface WithNestedDtoProjection {
3029
+ String getFirstname ();
3030
+ AddressDto getAddress ();
3031
+ }
3032
+
2984
3033
interface ProjectionWithNestedEntity {
2985
3034
2986
3035
Set <Address > getAddresses ();
@@ -2991,6 +3040,19 @@ interface AddressProjection {
2991
3040
String getStreet ();
2992
3041
}
2993
3042
3043
+ class AddressDto {
3044
+
3045
+ String street ;
3046
+
3047
+ public String getStreet () {
3048
+ return street ;
3049
+ }
3050
+
3051
+ public void setStreet (String street ) {
3052
+ this .street = street ;
3053
+ }
3054
+ }
3055
+
2994
3056
static class PersonDto {
2995
3057
2996
3058
LocalDate birthDate ;
0 commit comments