29
29
import org .springframework .data .mapping .PreferredConstructor ;
30
30
import org .springframework .data .mapping .PreferredConstructor .Parameter ;
31
31
import org .springframework .data .mapping .model .ParameterValueProvider ;
32
+ import org .springframework .data .neo4j .core .convert .Neo4jConversionService ;
32
33
import org .springframework .data .util .ClassTypeInformation ;
33
34
import org .springframework .data .util .ReflectionUtils ;
34
35
import org .springframework .lang .Nullable ;
@@ -46,6 +47,7 @@ public final class EntityFromDtoInstantiatingConverter<T> implements Converter<O
46
47
private final Neo4jMappingContext context ;
47
48
48
49
private final Map <Class <?>, EntityFromDtoInstantiatingConverter <?>> converterCache = new ConcurrentHashMap <>();
50
+ private final Neo4jConversionService conversionService ;
49
51
50
52
/**
51
53
* Creates a new {@link Converter} to instantiate Entities from DTOs.
@@ -60,6 +62,7 @@ public EntityFromDtoInstantiatingConverter(Class<T> entityType, Neo4jMappingCont
60
62
61
63
this .targetEntityType = entityType ;
62
64
this .context = context ;
65
+ this .conversionService = context .getConversionService ();
63
66
}
64
67
65
68
@ Override
@@ -131,9 +134,13 @@ Object getPropertyValueFor(PersistentProperty<?> targetProperty, PersistentEntit
131
134
}
132
135
133
136
if (propertyValue != null && !targetPropertyType .isInstance (propertyValue )) {
134
- EntityFromDtoInstantiatingConverter <?> nestedConverter = converterCache .computeIfAbsent (targetProperty .getType (),
135
- t -> new EntityFromDtoInstantiatingConverter <>(t , context ));
136
- return nestedConverter .convert (propertyValue );
137
+ if (conversionService .isSimpleType (targetPropertyType )) {
138
+ return conversionService .convert (propertyValue , targetPropertyType );
139
+ } else {
140
+ EntityFromDtoInstantiatingConverter <?> nestedConverter = converterCache .computeIfAbsent (targetProperty .getType (),
141
+ t -> new EntityFromDtoInstantiatingConverter <>(t , context ));
142
+ return nestedConverter .convert (propertyValue );
143
+ }
137
144
}
138
145
139
146
return propertyValue ;
0 commit comments