2121
2222import io .r2dbc .spi .Parameters ;
2323import io .r2dbc .spi .R2dbcType ;
24+ import io .r2dbc .spi .Row ;
2425import io .r2dbc .spi .test .MockColumnMetadata ;
2526import io .r2dbc .spi .test .MockResult ;
2627import io .r2dbc .spi .test .MockRow ;
6263import org .springframework .data .relational .core .query .Query ;
6364import org .springframework .data .relational .core .query .Update ;
6465import org .springframework .data .relational .core .sql .SqlIdentifier ;
66+ import org .springframework .data .relational .domain .RowDocument ;
6567import org .springframework .lang .Nullable ;
6668import org .springframework .r2dbc .core .DatabaseClient ;
6769import org .springframework .r2dbc .core .Parameter ;
@@ -88,7 +90,8 @@ void before() {
8890 client = DatabaseClient .builder ().connectionFactory (recorder )
8991 .bindMarkers (PostgresDialect .INSTANCE .getBindMarkersFactory ()).build ();
9092
91- R2dbcCustomConversions conversions = R2dbcCustomConversions .of (PostgresDialect .INSTANCE , new MoneyConverter ());
93+ R2dbcCustomConversions conversions = R2dbcCustomConversions .of (PostgresDialect .INSTANCE , new MoneyConverter (),
94+ new RowConverter (), new RowDocumentConverter ());
9295
9396 entityTemplate = new R2dbcEntityTemplate (client , PostgresDialect .INSTANCE ,
9497 new MappingR2dbcConverter (new R2dbcMappingContext (), conversions ));
@@ -611,6 +614,42 @@ void shouldConsiderParameterConverter() {
611614 Parameter .from (Parameters .in (R2dbcType .VARCHAR , "$$$" )));
612615 }
613616
617+ @ Test // GH-1696
618+ void shouldConsiderRowConverter () {
619+
620+ MockRowMetadata metadata = MockRowMetadata .builder ()
621+ .columnMetadata (MockColumnMetadata .builder ().name ("foo" ).type (R2dbcType .INTEGER ).build ())
622+ .columnMetadata (MockColumnMetadata .builder ().name ("bar" ).type (R2dbcType .VARCHAR ).build ()).build ();
623+ MockResult result = MockResult .builder ().row (MockRow .builder ().identified ("foo" , Object .class , 42 )
624+ .identified ("bar" , String .class , "the-bar" ).metadata (metadata ).build ()).build ();
625+
626+ recorder .addStubbing (s -> s .startsWith ("SELECT" ), result );
627+
628+ entityTemplate .select (MyRowToEntityType .class ).all ().as (StepVerifier ::create ) //
629+ .assertNext (actual -> {
630+ assertThat (actual .foo ).isEqualTo (1 ); // converter-fixed value
631+ assertThat (actual .bar ).isEqualTo ("the-bar" ); // converted value
632+ }).verifyComplete ();
633+ }
634+
635+ @ Test // GH-1696
636+ void shouldConsiderRowDocumentConverter () {
637+
638+ MockRowMetadata metadata = MockRowMetadata .builder ()
639+ .columnMetadata (MockColumnMetadata .builder ().name ("foo" ).type (R2dbcType .INTEGER ).build ())
640+ .columnMetadata (MockColumnMetadata .builder ().name ("bar" ).type (R2dbcType .VARCHAR ).build ()).build ();
641+ MockResult result = MockResult .builder ().row (MockRow .builder ().identified ("foo" , Object .class , 42 )
642+ .identified ("bar" , Object .class , "the-bar" ).metadata (metadata ).build ()).build ();
643+
644+ recorder .addStubbing (s -> s .startsWith ("SELECT" ), result );
645+
646+ entityTemplate .select (MyRowDocumentToEntityType .class ).all ().as (StepVerifier ::create ) //
647+ .assertNext (actual -> {
648+ assertThat (actual .foo ).isEqualTo (1 ); // converter-fixed value
649+ assertThat (actual .bar ).isEqualTo ("the-bar" ); // converted value
650+ }).verifyComplete ();
651+ }
652+
614653 record WithoutId (String name ) {
615654 }
616655
@@ -826,4 +865,30 @@ public io.r2dbc.spi.Parameter convert(Money source) {
826865 }
827866
828867 }
868+
869+ record MyRowToEntityType (int foo , String bar ) {
870+
871+ }
872+
873+ static class RowConverter implements Converter <Row , MyRowToEntityType > {
874+
875+ @ Override
876+ public MyRowToEntityType convert (Row source ) {
877+ return new MyRowToEntityType (1 , source .get ("bar" , String .class ));
878+ }
879+
880+ }
881+
882+ record MyRowDocumentToEntityType (int foo , String bar ) {
883+
884+ }
885+
886+ static class RowDocumentConverter implements Converter <RowDocument , MyRowDocumentToEntityType > {
887+
888+ @ Override
889+ public MyRowDocumentToEntityType convert (RowDocument source ) {
890+ return new MyRowDocumentToEntityType (1 , (String ) source .get ("bar" ));
891+ }
892+
893+ }
829894}
0 commit comments