@@ -336,9 +336,13 @@ private Optional<Object> readReference(
336
336
final ArangoPersistentProperty property ,
337
337
final Annotation annotation ) {
338
338
339
+ if (source .isNone () || source .isNull ()) {
340
+ return Optional .empty ();
341
+ }
342
+
339
343
final Optional <ReferenceResolver <Annotation >> resolver = resolverFactory .getReferenceResolver (annotation );
340
344
341
- if (!resolver .isPresent () || source . isNone () ) {
345
+ if (!resolver .isPresent ()) {
342
346
return Optional .empty ();
343
347
}
344
348
@@ -353,6 +357,11 @@ else if (property.isCollectionLike()) {
353
357
return resolver .map (res -> res .resolveMultiple (ids , property .getTypeInformation (), annotation ));
354
358
}
355
359
360
+ else if (source .isObject ()) {
361
+ // source contains target
362
+ return Optional .of (readInternal (property .getTypeInformation (), source ));
363
+ }
364
+
356
365
else {
357
366
if (!source .isString ()) {
358
367
throw new MappingException (
@@ -370,6 +379,10 @@ private <A extends Annotation> Optional<Object> readRelation(
370
379
final ArangoPersistentProperty property ,
371
380
final A annotation ) {
372
381
382
+ if (source .isNull ()) {
383
+ return Optional .empty ();
384
+ }
385
+
373
386
final Class <? extends Annotation > collectionType = entity .findAnnotation (Edge .class ) != null ? Edge .class
374
387
: Document .class ;
375
388
final Optional <RelationResolver <Annotation >> resolver = resolverFactory .getRelationResolver (annotation ,
@@ -383,16 +396,26 @@ private <A extends Annotation> Optional<Object> readRelation(
383
396
}
384
397
385
398
else if (property .isCollectionLike ()) {
399
+ if (source .isArray ()) {
400
+ // source contains target array
401
+ return Optional .of (readInternal (property .getTypeInformation (), source ));
402
+ }
386
403
if (parentId == null ) {
387
404
return Optional .empty ();
388
405
}
389
406
return resolver .map (res -> res .resolveMultiple (parentId , property .getTypeInformation (), traversedTypes , annotation ));
390
407
}
391
408
392
409
else if (source .isString ()) {
410
+ // resolve from/to using target id
393
411
return resolver .map (res -> res .resolveOne (source .getAsString (), property .getTypeInformation (), traversedTypes , annotation ));
394
412
}
395
413
414
+ else if (source .isObject ()) {
415
+ // source contains target
416
+ return Optional .of (readInternal (property .getTypeInformation (), source ));
417
+ }
418
+
396
419
else {
397
420
return resolver .map (res -> res .resolveOne (parentId , property .getTypeInformation (), traversedTypes , annotation ));
398
421
}
0 commit comments