1616package org .springframework .data .neo4j .core .mapping ;
1717
1818import java .lang .reflect .Field ;
19+ import java .lang .reflect .ParameterizedType ;
1920import java .util .Collections ;
2021import java .util .Optional ;
2122
23+ import org .springframework .core .ResolvableType ;
2224import org .springframework .data .annotation .ReadOnlyProperty ;
2325import org .springframework .data .mapping .Association ;
2426import org .springframework .data .mapping .MappingException ;
@@ -117,8 +119,8 @@ protected Association<Neo4jPersistentProperty> createAssociation() {
117119 Neo4jPersistentEntity <?> relationshipPropertiesClass = null ;
118120
119121 if (this .hasActualTypeAnnotation (RelationshipProperties .class )) {
120- Class <?> type = getRelationshipPropertiesTargetType (getActualType ());
121- obverseOwner = this .mappingContext .addPersistentEntity (TypeInformation . of ( type ) ).get ();
122+ TypeInformation <?> typeInformation = getRelationshipPropertiesTargetType (getActualType ());
123+ obverseOwner = this .mappingContext .addPersistentEntity (typeInformation ).get ();
122124 relationshipPropertiesClass = this .mappingContext .addPersistentEntity (TypeInformation .of (getActualType ())).get ();
123125 } else {
124126 Class <?> associationTargetType = this .getAssociationTargetType ();
@@ -136,8 +138,8 @@ protected Association<Neo4jPersistentProperty> createAssociation() {
136138 mapValueType .getType ().isAnnotationPresent (RelationshipProperties .class );
137139
138140 if (relationshipPropertiesCollection ) {
139- Class <?> type = getRelationshipPropertiesTargetType (mapValueType .getActualType ().getType ());
140- obverseOwner = this .mappingContext .addPersistentEntity (TypeInformation . of ( type ) ).get ();
141+ TypeInformation <?> typeInformation = getRelationshipPropertiesTargetType (mapValueType .getActualType ().getType ());
142+ obverseOwner = this .mappingContext .addPersistentEntity (typeInformation ).get ();
141143 relationshipPropertiesClass = this .mappingContext
142144 .addPersistentEntity (mapValueType .getComponentType ()).get ();
143145
@@ -179,7 +181,7 @@ protected Association<Neo4jPersistentProperty> createAssociation() {
179181 }
180182
181183 @ NonNull
182- private Class <?> getRelationshipPropertiesTargetType (Class <?> relationshipPropertiesType ) {
184+ private TypeInformation <?> getRelationshipPropertiesTargetType (Class <?> relationshipPropertiesType ) {
183185
184186 Field targetNodeField = ReflectionUtils .findField (relationshipPropertiesType ,
185187 field -> field .isAnnotationPresent (TargetNode .class ));
@@ -188,7 +190,11 @@ private Class<?> getRelationshipPropertiesTargetType(Class<?> relationshipProper
188190 throw new MappingException ("Missing @TargetNode declaration in " + relationshipPropertiesType );
189191 }
190192 TypeInformation <?> relationshipPropertiesTypeInformation = TypeInformation .of (relationshipPropertiesType );
191- return relationshipPropertiesTypeInformation .getProperty (targetNodeField .getName ()).getType ();
193+ Class <?> type = relationshipPropertiesTypeInformation .getProperty (targetNodeField .getName ()).getType ();
194+ if (Object .class == type && this .getField ().getGenericType () instanceof ParameterizedType pt && pt .getActualTypeArguments ().length == 1 ) {
195+ return TypeInformation .of (ResolvableType .forType (pt .getActualTypeArguments ()[0 ]));
196+ }
197+ return TypeInformation .of (type );
192198 }
193199
194200 @ Override
0 commit comments