@@ -657,9 +657,9 @@ private void writeProperty(final Object source, final VPackBuilder sink, final A
657657
658658 if (property .getRef ().isPresent ()) {
659659 if (sourceType .isCollectionLike ()) {
660- writeReferences (fieldName , source , sink );
660+ writeReferences (fieldName , source , sink , property . getRef (). get () );
661661 } else {
662- writeReference (fieldName , source , sink );
662+ writeReference (fieldName , source , sink , property . getRef (). get () );
663663 }
664664 }
665665
@@ -669,7 +669,7 @@ else if (property.getRelations().isPresent()) {
669669
670670 else if (property .getFrom ().isPresent () || property .getTo ().isPresent ()) {
671671 if (!sourceType .isCollectionLike ()) {
672- writeReference (fieldName , source , sink );
672+ writeReference (fieldName , source , sink , null );
673673 }
674674 }
675675
@@ -732,27 +732,27 @@ private void writeArray(
732732 }
733733 }
734734
735- private void writeReferences (final String attribute , final Object source , final VPackBuilder sink ) {
735+ private void writeReferences (final String attribute , final Object source , final VPackBuilder sink , final Ref annotation ) {
736736 sink .add (attribute , ValueType .ARRAY );
737737
738738 if (source .getClass ().isArray ()) {
739739 for (int i = 0 ; i < Array .getLength (source ); ++i ) {
740740 final Object element = Array .get (source , i );
741- writeReference (null , element , sink );
741+ writeReference (null , element , sink , annotation );
742742 }
743743 }
744744
745745 else {
746746 for (final Object element : asCollection (source )) {
747- writeReference (null , element , sink );
747+ writeReference (null , element , sink , annotation );
748748 }
749749 }
750750
751751 sink .close ();
752752 }
753753
754- private void writeReference (final String attribute , final Object source , final VPackBuilder sink ) {
755- getRefId (source ).ifPresent (id -> sink .add (attribute , id ));
754+ private void writeReference (final String attribute , final Object source , final VPackBuilder sink , final Ref annotation ) {
755+ getRefId (source , annotation ).ifPresent (id -> sink .add (attribute , id ));
756756 }
757757
758758 @ SuppressWarnings ("unchecked" )
@@ -867,18 +867,24 @@ private void writeBaseEdgeDocument(
867867 sink .add (attribute , builder .slice ());
868868 }
869869
870- private Optional <String > getRefId (final Object source ) {
871- return getRefId (source , context .getPersistentEntity (source .getClass ()));
870+ private Optional <String > getRefId (final Object source , final Ref annotation ) {
871+ return getRefId (source , context .getPersistentEntity (source .getClass ()), annotation );
872872 }
873873
874- private Optional <String > getRefId (final Object source , final ArangoPersistentEntity <?> entity ) {
874+ private Optional <String > getRefId (final Object source , final ArangoPersistentEntity <?> entity , final Ref annotation ) {
875875 if (source instanceof LazyLoadingProxy ) {
876876 return Optional .of (((LazyLoadingProxy ) source ).getRefId ());
877877 }
878878
879879 final Optional <Object > id = Optional .ofNullable (entity .getIdentifierAccessor (source ).getIdentifier ());
880880 if (id .isPresent ()) {
881- return id .map (key -> MetadataUtils .createIdFromCollectionAndKey (entity .getCollection (), convertId (key )));
881+ if (annotation != null ){
882+ final Optional <ReferenceResolver <Annotation >> resolver = resolverFactory .getReferenceResolver (annotation );
883+ return id .map (key -> resolver .get ().write (source , entity , convertId (key ),annotation ));
884+ } else {
885+ return id .map (key -> MetadataUtils .createIdFromCollectionAndKey (entity .getCollection (), convertId (key )));
886+ }
887+
882888 }
883889
884890 return Optional .ofNullable ((String ) entity .getArangoIdAccessor (source ).getIdentifier ());
0 commit comments