@@ -376,7 +376,9 @@ protected Document getMappedKeyword(Keyword keyword, @Nullable MongoPersistentEn
376
376
if (keyword .isOrOrNor () || (keyword .hasIterableValue () && !keyword .isGeometry ())) {
377
377
378
378
Iterable <?> conditions = keyword .getValue ();
379
- List <Object > newConditions = conditions instanceof Collection ? new ArrayList <>(((Collection <?>) conditions ).size ()) : new ArrayList <>();
379
+ List <Object > newConditions = conditions instanceof Collection
380
+ ? new ArrayList <>(((Collection <?>) conditions ).size ())
381
+ : new ArrayList <>();
380
382
381
383
for (Object condition : conditions ) {
382
384
newConditions .add (isDocument (condition ) ? getMappedObject ((Document ) condition , entity )
@@ -434,8 +436,10 @@ protected Object getMappedValue(Field documentField, Object sourceValue) {
434
436
435
437
Object value = applyFieldTargetTypeHintToValue (documentField , sourceValue );
436
438
437
- if (documentField .getProperty () != null && converter .getCustomConversions ().getPropertyValueConversions ().hasValueConverter (documentField .getProperty ())) {
438
- return converter .getCustomConversions ().getPropertyValueConversions ().getValueConverter (documentField .getProperty ())
439
+ if (documentField .getProperty () != null
440
+ && converter .getCustomConversions ().getPropertyValueConversions ().hasValueConverter (documentField .getProperty ())) {
441
+ return converter .getCustomConversions ().getPropertyValueConversions ()
442
+ .getValueConverter (documentField .getProperty ())
439
443
.write (value , new MongoConversionContext (documentField .getProperty (), converter ));
440
444
}
441
445
@@ -619,7 +623,11 @@ protected Object delegateConvertToMongoType(Object source, @Nullable MongoPersis
619
623
}
620
624
621
625
protected Object convertAssociation (Object source , Field field ) {
622
- return convertAssociation (source , field .getProperty ());
626
+ Object value = convertAssociation (source , field .getProperty ());
627
+ if (value != null && field .isIdField () && field .getFieldType () != value .getClass ()) {
628
+ return convertId (value , field .getFieldType ());
629
+ }
630
+ return value ;
623
631
}
624
632
625
633
/**
@@ -1045,6 +1053,9 @@ public TypeInformation<?> getTypeHint() {
1045
1053
return ClassTypeInformation .OBJECT ;
1046
1054
}
1047
1055
1056
+ public Class <?> getFieldType () {
1057
+ return Object .class ;
1058
+ }
1048
1059
}
1049
1060
1050
1061
/**
@@ -1197,10 +1208,11 @@ private Association<MongoPersistentProperty> findAssociation() {
1197
1208
return null ;
1198
1209
}
1199
1210
1200
- /*
1201
- * (non-Javadoc)
1202
- * @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#getTargetKey()
1203
- */
1211
+ @ Override
1212
+ public Class <?> getFieldType () {
1213
+ return property .getFieldType ();
1214
+ }
1215
+
1204
1216
@ Override
1205
1217
public String getMappedKey () {
1206
1218
return path == null ? name : path .toDotPath (isAssociation () ? getAssociationConverter () : getPropertyConverter ());
0 commit comments