Hi,
I have a parent class with a polymorphic child member. Adding entities via a Spring-Data-REST repository works fine, but editing (via PATCH) doesn't change the type of the child member, only its attributes.
The parent code is as follows (without getters/setters and some irrelevant JPA annotations):
The code of the child is as follows (again, irrelevant fields omitted):
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "@type")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
publicabstractclassChild {
// Some common fields, including an ID@JsonProperty("@type")
publicStringgetType() {
returngetClass().getName();
}
}
The subclasses don't add anything but some simple fields with no references to other entities.
Upon submitting valid JSON to the ParentRepository (extending CrudRepository<Parent, Long>), all fields get merged but the @type property of the child is ignored. This is because of this code in DomainObjectReader:
if (!mappedProperties.hasPersistentPropertyForField(fieldName)) {
continue;
}
The @type property is obviously not a persistent property, so it gets ignored.
Is there a fix for this or am I missing anything?
Affects: 2.6.9 (Ingalls SR9)
The text was updated successfully, but these errors were encountered:
Fabian Günter opened DATAREST-1186 and commented
Hi,
I have a parent class with a polymorphic child member. Adding entities via a Spring-Data-REST repository works fine, but editing (via PATCH) doesn't change the type of the child member, only its attributes.
The parent code is as follows (without getters/setters and some irrelevant JPA annotations):
The code of the child is as follows (again, irrelevant fields omitted):
The subclasses don't add anything but some simple fields with no references to other entities.
Upon submitting valid JSON to the ParentRepository (extending CrudRepository<Parent, Long>), all fields get merged but the
@type
property of the child is ignored. This is because of this code in DomainObjectReader:The
@type
property is obviously not a persistent property, so it gets ignored.Is there a fix for this or am I missing anything?
Affects: 2.6.9 (Ingalls SR9)
The text was updated successfully, but these errors were encountered: