@@ -64,7 +64,8 @@ void before() {
6464
6565 R2dbcCustomConversions conversions = new R2dbcCustomConversions (
6666 Arrays .asList (StringToMapConverter .INSTANCE , MapToStringConverter .INSTANCE ,
67- CustomConversionPersonToOutboundRowConverter .INSTANCE , RowToCustomConversionPerson .INSTANCE ));
67+ CustomConversionPersonToOutboundRowConverter .INSTANCE , RowToCustomConversionPerson .INSTANCE ,
68+ StringToSimplePersonConverter .INSTANCE ));
6869
6970 mappingContext .setSimpleTypeHolder (conversions .getSimpleTypeHolder ());
7071
@@ -81,8 +82,7 @@ void shouldIncludeAllPropertiesInOutboundRow() {
8182 converter .write (new Person ("id" , "Walter" , "White" , instant , localDateTime ), row );
8283
8384 assertThat (row ).containsEntry (SqlIdentifier .unquoted ("id" ), Parameter .fromOrEmpty ("id" , String .class ));
84- assertThat (row ).containsEntry (SqlIdentifier .unquoted ("firstname" ),
85- Parameter .fromOrEmpty ("Walter" , String .class ));
85+ assertThat (row ).containsEntry (SqlIdentifier .unquoted ("firstname" ), Parameter .fromOrEmpty ("Walter" , String .class ));
8686 assertThat (row ).containsEntry (SqlIdentifier .unquoted ("lastname" ), Parameter .fromOrEmpty ("White" , String .class ));
8787 assertThat (row ).containsEntry (SqlIdentifier .unquoted ("instant" ), Parameter .from (instant ));
8888 assertThat (row ).containsEntry (SqlIdentifier .unquoted ("local_date_time" ), Parameter .from (localDateTime ));
@@ -236,6 +236,19 @@ void shouldEvaluateSpelExpression() {
236236 assertThat (result .world ).isEqualTo ("No, universe" );
237237 }
238238
239+ @ Test // GH-670
240+ void considersConverterBeforeEntityConstruction () {
241+
242+ MockRow row = MockRow .builder ().identified ("id" , Object .class , 42 ).identified ("person" , Object .class , null ).build ();
243+ MockRowMetadata metadata = MockRowMetadata .builder ().columnMetadata (MockColumnMetadata .builder ().name ("id" ).build ())
244+ .columnMetadata (MockColumnMetadata .builder ().name ("person" ).build ()).build ();
245+
246+ WithSimplePersonConstructor result = converter .read (WithSimplePersonConstructor .class , row , metadata );
247+
248+ assertThat (result .id ).isEqualTo (42 );
249+ assertThat (result .person ).isNull ();
250+ }
251+
239252 @ AllArgsConstructor
240253 static class Person {
241254 @ Id String id ;
@@ -349,6 +362,17 @@ public CustomConversionPerson convert(Row source) {
349362 }
350363 }
351364
365+ @ ReadingConverter
366+ enum StringToSimplePersonConverter implements Converter <String , SimplePerson > {
367+
368+ INSTANCE ;
369+
370+ @ Override
371+ public SimplePerson convert (String source ) {
372+ return new SimplePerson (source );
373+ }
374+ }
375+
352376 static class WithSpelExpression {
353377
354378 private final long id ;
@@ -361,4 +385,24 @@ public WithSpelExpression(long id, @Value("null") String hello, @Value("#root.wo
361385 this .world = world ;
362386 }
363387 }
388+
389+ static class WithSimplePersonConstructor {
390+
391+ private final long id ;
392+ private final SimplePerson person ;
393+
394+ public WithSimplePersonConstructor (long id , SimplePerson person ) {
395+ this .id = id ;
396+ this .person = person ;
397+ }
398+ }
399+
400+ static class SimplePerson {
401+
402+ private final String name ;
403+
404+ SimplePerson (String name ) {
405+ this .name = name ;
406+ }
407+ }
364408}
0 commit comments