spring-projects / spring-projects/spring-data-rest
Null Pointer in PersistentEntityResourceAssembler when using InheritanceType.JOINED [DATAREST-760]
@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
Andrew Glassman opened DATAREST-760 and commented
I have an issue with @RepositoryRestResource returning a 500 error due to a null pointer.
I have an abstract class named Resource which uses InheritanceType.JOINED and @JsonSubTypes to provide about 5 subclasses of Resource such as ServerResource, NetworkResource, etc. The specific subclass of Resource is returned fine when referenced in another entity that it joins with. The PagingAndSortingRepository also works fine when called in code (not via an endpoint). The problem is the endpoint exposed by @RepositoryRestResource for the Resource entity returns a 500 error (due to NPE) when called directly.
After debugging, I found the issue is due to the line PersistentEntityResourceAssembler:154. The mapping object is null because the framework could not map ServerResource.class to the parent Resource.class. The cache is a map, and uses .getClass(). Therefor, it is unable to be marshaled to JSON.
I detailed my hack to fix the cache in the StackOverflow post linked in the Reference URL. I haven't looked into what an appropriate fix to get the Resource subclasses into the map
Reference URL: http://stackoverflow.com/questions/32847852/spring-data-rest-null-pointer-in-persistententityresourceassembler
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.