16
16
package org .springframework .data .neo4j .core .mapping ;
17
17
18
18
import java .lang .reflect .Field ;
19
+ import java .lang .reflect .ParameterizedType ;
19
20
import java .util .Collections ;
20
21
import java .util .Optional ;
21
22
23
+ import org .springframework .core .ResolvableType ;
22
24
import org .springframework .data .annotation .ReadOnlyProperty ;
23
25
import org .springframework .data .mapping .Association ;
24
26
import org .springframework .data .mapping .MappingException ;
@@ -117,8 +119,8 @@ protected Association<Neo4jPersistentProperty> createAssociation() {
117
119
Neo4jPersistentEntity <?> relationshipPropertiesClass = null ;
118
120
119
121
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 ();
122
124
relationshipPropertiesClass = this .mappingContext .addPersistentEntity (TypeInformation .of (getActualType ())).get ();
123
125
} else {
124
126
Class <?> associationTargetType = this .getAssociationTargetType ();
@@ -136,8 +138,8 @@ protected Association<Neo4jPersistentProperty> createAssociation() {
136
138
mapValueType .getType ().isAnnotationPresent (RelationshipProperties .class );
137
139
138
140
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 ();
141
143
relationshipPropertiesClass = this .mappingContext
142
144
.addPersistentEntity (mapValueType .getComponentType ()).get ();
143
145
@@ -179,7 +181,7 @@ protected Association<Neo4jPersistentProperty> createAssociation() {
179
181
}
180
182
181
183
@ NonNull
182
- private Class <?> getRelationshipPropertiesTargetType (Class <?> relationshipPropertiesType ) {
184
+ private TypeInformation <?> getRelationshipPropertiesTargetType (Class <?> relationshipPropertiesType ) {
183
185
184
186
Field targetNodeField = ReflectionUtils .findField (relationshipPropertiesType ,
185
187
field -> field .isAnnotationPresent (TargetNode .class ));
@@ -188,7 +190,11 @@ private Class<?> getRelationshipPropertiesTargetType(Class<?> relationshipProper
188
190
throw new MappingException ("Missing @TargetNode declaration in " + relationshipPropertiesType );
189
191
}
190
192
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 );
192
198
}
193
199
194
200
@ Override
0 commit comments