spring-projects / spring-projects/spring-data-rest
Cannot return plain string from @BasePathAwareController method [DATAREST-1323]
@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
Doogiemuc opened DATAREST-1323 and commented
It is not possible to return a plain String from a rest controller when it is annotated with @BasePathAwareController.
This normal controller works (but in this controller I for example couldn't inject PersistentEntityResourceAssembler)
@RestController
@RequestMapping("${spring.data.rest.base-path}") // to expose under correct basepath
public class UserRestController {
@RequestMapping("/getStringExample")
public @ResponseBody String getStringExample() {
return "Some dummy String"
}
}
But this does not work:
@BasePathAwareController
public class UserRestController {
@RequestMapping("/getStringExample")
public @ResponseBody String getStringExample() {
return "Some dummy String"
}
}
This returns a quoted string. Adding produces = "text/plain" also doesn't help. It doesn't work no matter if you use @ResponseBody or not.
Even when you return a ResponseEntity.ok("Some dummy String"); the result will still be quoted in the final response.
How can I return a plain String (e.g. a token) from a @BasePathAwareController?
Reference URL: https://stackoverflow.com/questions/33687722/spring-data-rest-custom-method-return-string
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.