spring-projects / spring-projects/spring-data-rest

Cannot return plain string from @BasePathAwareController method [DATAREST-1323]

Open
#1,682 0 comments 1 reaction 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: repository type: bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.