spring-projects / spring-projects/spring-data-rest
Unmapped values, when using @JsonTypeInfo [DATAREST-166]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Johannes Hiemer opened DATAREST-166 and commented
At the moment I have the following scenario setup: I have a class called Test, which is base class for different entities. This class gets extended by ExtendedTest. To do a POST on their repositories I am using the following URL and body:
POST http://localhost:8080/web/tests
{ "entities" : ["iorioriooi", "iufiuuifui"],
"extendedEntities" : "contents123" }
200 OK
{ "entities" : [ "iorioriooi", "iufiuuifui" ],
"links" : [ {
"rel" : "self",
"href" : "http://localhost:8080/web/tests/5243c4aba0eef1cbee89c5ef"
}]}
As you can see here, although no exception was thrown extendedEntities was not persisted. Afterwards I added @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
to Test and tried again. My request looked all the same, except the specification of the class:
POST http://localhost:8080/web/tests
{ "@class" : "de.model.nosql.test.ExtendedTest",
"entities" : ["iorioriooi", "iufiuuifui"],
"extendedEntities" : "contents123" }
200 OK
{ "extendedEntities" : "contents123",
"entities" : null,
"links" : [ {
"rel" : "self",
"href" : "http://localhost:8080/web/extendedTests/5243c632a0ee8d4f2f795aa6"
}]}
As you can see now, the class ExtendedTest is used, and extendedEntities is filled, while entities from Test is ignored. But that's not always the case. I added String baseEntities to test, whether all types are ignored when doing a POST via the @class annotation. Again, the request URL was the same:
POST http://localhost:8080/web/tests
{ "@class" : "de.model.nosql.test.ExtendedTest",
"entities" : ["iorioriooi", "iufiuuifui"],
"extendedEntities" : "contents123",
"baseEntities" : "contents123" }
200 OK
{ "extendedEntities" : "contents123",
"entities" : null,
"baseEntities" : "contents123",
"links" : [ {
"rel" : "self",
"href" : "http://localhost:8080/web/extendedTests/5243c71da0ee6310f996be26"
}]}
As you can see here, the baseEntities not being a list and instead just a String, are not ignore and working properly. This applies to all objects not nested in a list.
I attached the source files, as well as the screenshots of all three test runs. Any idea why this happens?
Affects: 2.0 M1 (Codd)
Attachments:
- test.zip (1.52 kB)
- testRepositories.zip (921 bytes)
- with jsontype.png (206.46 kB)
- with jsontype and String in base class.png (229.87 kB)
- without jsontype.png (209.00 kB)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.