spring-projects / spring-projects/spring-data-rest
Unwanted conversion of Generic Data Type to LinkedHashMap [DATAREST-973]
@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
Roy Krisnadi opened DATAREST-973 and commented
I tried to create SpringBoot Rest
Here's my controller:
@PostMapping
public Response add( Category category) {
// try to insert category to db and return Response
Response<Category> response = categoryService.insert(category);
return response;
}
Response:
// This contains the result, which in this case will be Category
public class Response<T> {
// other fields and getter setter is not included
private T result;
public T getResult() {
return result;
}
public void setResult(T result) {
this.result = result;
}
Category Service insert:
public Response<T> insert(@NotNull final T bean) {
Response<T> response = new Response<>();
bean.setCreated(context.now());
// The repository is an interface that extends MongoRepository<Category, String>
response.setResult(repository.save(bean));
response.setSuccess(true);
return response;
}
Problem:
When I tried to test the controller as the picture attached
I am expecting to get Category back, instead I get LinkedListMap that I is converted from Category.
I believe the problem is because when I use the generic type, spring will think that it's just a regular Object then convert it to Map.
Expectation:
Spring should return response.getResult() as Category
!SpringTest.JPG|thumbnail!
Sorry I'm not really sure which version of Spring Data Rest this Spring Boot 1.4.3 uses. Maybe I even posting it on the wrong project. But I do my best to create this JIRA hoping that this will be investigated. Thanks
Attachments:
- SpringTest.JPG (275.21 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.