@@ -65,7 +65,8 @@ void before() {
65
65
66
66
R2dbcCustomConversions conversions = R2dbcCustomConversions .of (PostgresDialect .INSTANCE ,
67
67
Arrays .asList (StringToMapConverter .INSTANCE , MapToStringConverter .INSTANCE ,
68
- CustomConversionPersonToOutboundRowConverter .INSTANCE , RowToCustomConversionPerson .INSTANCE ));
68
+ CustomConversionPersonToOutboundRowConverter .INSTANCE , RowToCustomConversionPerson .INSTANCE ,
69
+ StringToSimplePersonConverter .INSTANCE ));
69
70
70
71
mappingContext .setSimpleTypeHolder (conversions .getSimpleTypeHolder ());
71
72
@@ -82,8 +83,7 @@ void shouldIncludeAllPropertiesInOutboundRow() {
82
83
converter .write (new Person ("id" , "Walter" , "White" , instant , localDateTime ), row );
83
84
84
85
assertThat (row ).containsEntry (SqlIdentifier .unquoted ("id" ), Parameter .fromOrEmpty ("id" , String .class ));
85
- assertThat (row ).containsEntry (SqlIdentifier .unquoted ("firstname" ),
86
- Parameter .fromOrEmpty ("Walter" , String .class ));
86
+ assertThat (row ).containsEntry (SqlIdentifier .unquoted ("firstname" ), Parameter .fromOrEmpty ("Walter" , String .class ));
87
87
assertThat (row ).containsEntry (SqlIdentifier .unquoted ("lastname" ), Parameter .fromOrEmpty ("White" , String .class ));
88
88
assertThat (row ).containsEntry (SqlIdentifier .unquoted ("instant" ), Parameter .from (instant ));
89
89
assertThat (row ).containsEntry (SqlIdentifier .unquoted ("local_date_time" ), Parameter .from (localDateTime ));
@@ -237,6 +237,19 @@ void shouldEvaluateSpelExpression() {
237
237
assertThat (result .world ).isEqualTo ("No, universe" );
238
238
}
239
239
240
+ @ Test // GH-670
241
+ void considersConverterBeforeEntityConstruction () {
242
+
243
+ MockRow row = MockRow .builder ().identified ("id" , Object .class , 42 ).identified ("person" , Object .class , null ).build ();
244
+ MockRowMetadata metadata = MockRowMetadata .builder ().columnMetadata (MockColumnMetadata .builder ().name ("id" ).build ())
245
+ .columnMetadata (MockColumnMetadata .builder ().name ("person" ).build ()).build ();
246
+
247
+ WithSimplePersonConstructor result = converter .read (WithSimplePersonConstructor .class , row , metadata );
248
+
249
+ assertThat (result .id ).isEqualTo (42 );
250
+ assertThat (result .person ).isNull ();
251
+ }
252
+
240
253
@ AllArgsConstructor
241
254
static class Person {
242
255
@ Id String id ;
@@ -350,6 +363,17 @@ public CustomConversionPerson convert(Row source) {
350
363
}
351
364
}
352
365
366
+ @ ReadingConverter
367
+ enum StringToSimplePersonConverter implements Converter <String , SimplePerson > {
368
+
369
+ INSTANCE ;
370
+
371
+ @ Override
372
+ public SimplePerson convert (String source ) {
373
+ return new SimplePerson (source );
374
+ }
375
+ }
376
+
353
377
static class WithSpelExpression {
354
378
355
379
private final long id ;
@@ -362,4 +386,24 @@ public WithSpelExpression(long id, @Value("null") String hello, @Value("#root.wo
362
386
this .world = world ;
363
387
}
364
388
}
389
+
390
+ static class WithSimplePersonConstructor {
391
+
392
+ private final long id ;
393
+ private final SimplePerson person ;
394
+
395
+ public WithSimplePersonConstructor (long id , SimplePerson person ) {
396
+ this .id = id ;
397
+ this .person = person ;
398
+ }
399
+ }
400
+
401
+ static class SimplePerson {
402
+
403
+ private final String name ;
404
+
405
+ SimplePerson (String name ) {
406
+ this .name = name ;
407
+ }
408
+ }
365
409
}
0 commit comments