You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking at #2130 and its commit (adcd7e7). This fixed the situation for a PUT request when the type changes from a superclass to a subclass (e.g. Animal => Bird), such that the saved entity would correctly be the new subclass type. The implementation (an instance check) got me suspicious that inverse would not work correctly: that changing from the subtype to the supertype would not change the type of the object. I checked it out using Spring Data MongoDB, and my suspicion proved to be correct.
Expected behavior
When updating a REST entity using PUT, the Jackson type of the result should be used.
Actual behavior
When updating a REST entity using PUT, the Jackson type of the result is not used when the type of the request (per Jackson) is a supertype of the type of the existing saved entity. Instead, the REST entity type remains unchanged as the subclass type.
Example
Given the following Spring Data MongoDB document classes:
This uses Jackson deduction-based polymorphism such that if an instance has an airSpeedVelocity, it is a Bird; if it does not, it is a non-bird Animal. For example, {"name": "Swallow", "airSpeedVelocity": 20} is treated by Jackson as a Bird, but {"name": "Cat"} is treated as a non-bird Animal.
Tests
Given the following two tests, updateAnimalToBird passes, but updateBirdToAnimal fails.
I was looking at #2130 and its commit (adcd7e7). This fixed the situation for a PUT request when the type changes from a superclass to a subclass (e.g.
Animal
=>Bird
), such that the saved entity would correctly be the new subclass type. The implementation (an instance check) got me suspicious that inverse would not work correctly: that changing from the subtype to the supertype would not change the type of the object. I checked it out using Spring Data MongoDB, and my suspicion proved to be correct.Expected behavior
When updating a REST entity using
PUT
, the Jackson type of the result should be used.Actual behavior
When updating a REST entity using
PUT
, the Jackson type of the result is not used when the type of the request (per Jackson) is a supertype of the type of the existing saved entity. Instead, the REST entity type remains unchanged as the subclass type.Example
Given the following Spring Data MongoDB document classes:
This uses Jackson deduction-based polymorphism such that if an instance has an
airSpeedVelocity
, it is aBird
; if it does not, it is a non-birdAnimal
. For example,{"name": "Swallow", "airSpeedVelocity": 20}
is treated by Jackson as aBird
, but{"name": "Cat"}
is treated as a non-birdAnimal
.Tests
Given the following two tests,
updateAnimalToBird
passes, butupdateBirdToAnimal
fails.The text was updated successfully, but these errors were encountered: