@@ -64,7 +64,8 @@ void before() {
64
64
65
65
R2dbcCustomConversions conversions = new R2dbcCustomConversions (
66
66
Arrays .asList (StringToMapConverter .INSTANCE , MapToStringConverter .INSTANCE ,
67
- CustomConversionPersonToOutboundRowConverter .INSTANCE , RowToCustomConversionPerson .INSTANCE ));
67
+ CustomConversionPersonToOutboundRowConverter .INSTANCE , RowToCustomConversionPerson .INSTANCE ,
68
+ StringToSimplePersonConverter .INSTANCE ));
68
69
69
70
mappingContext .setSimpleTypeHolder (conversions .getSimpleTypeHolder ());
70
71
@@ -81,8 +82,7 @@ void shouldIncludeAllPropertiesInOutboundRow() {
81
82
converter .write (new Person ("id" , "Walter" , "White" , instant , localDateTime ), row );
82
83
83
84
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 ));
86
86
assertThat (row ).containsEntry (SqlIdentifier .unquoted ("lastname" ), Parameter .fromOrEmpty ("White" , String .class ));
87
87
assertThat (row ).containsEntry (SqlIdentifier .unquoted ("instant" ), Parameter .from (instant ));
88
88
assertThat (row ).containsEntry (SqlIdentifier .unquoted ("local_date_time" ), Parameter .from (localDateTime ));
@@ -236,6 +236,19 @@ void shouldEvaluateSpelExpression() {
236
236
assertThat (result .world ).isEqualTo ("No, universe" );
237
237
}
238
238
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
+
239
252
@ AllArgsConstructor
240
253
static class Person {
241
254
@ Id String id ;
@@ -349,6 +362,17 @@ public CustomConversionPerson convert(Row source) {
349
362
}
350
363
}
351
364
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
+
352
376
static class WithSpelExpression {
353
377
354
378
private final long id ;
@@ -361,4 +385,24 @@ public WithSpelExpression(long id, @Value("null") String hello, @Value("#root.wo
361
385
this .world = world ;
362
386
}
363
387
}
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
+ }
364
408
}
0 commit comments