0

I have class:

@RepositoryRestController
@RequestMapping(value = "users")
public class UserController  {

...other methods...

@GetMapping(value = "returnText", produces = MediaType.TEXT_PLAIN_VALUE)
    public String returnText() {
        return "my text";
    }
}

And when this method is called by Postman, http response content-type header is application/hal+json but I used produces = MediaType.TEXT_PLAIN_VALUE.

Can I somehow change content-type header of response?

Can @RepositoryRestController only return application/hal+json?

I wanted to use @RepositoryRestController to return image/jpg contet-type also in another method and that does not work because of same reason.

I think this will work in @RestController class but why use that if my application is Spring Data Rest and I want to use @RepositoryRestController annotation for my controllers.

lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
st.
  • 87
  • 4
  • Please have a look at this maybe this can help. visit https://stackoverflow.com/questions/5556897/changing-content-type-in-jax-rs-rest-service – Ashutosh Sahu Apr 06 '18 at 17:11
  • That are jax-rs not Spring annotations. So I don't think that will help me, but thanks. – st. Apr 06 '18 at 17:36

1 Answers1

0

From SDR documentation:

...to take advantage of Spring Data REST’s settings, message converters, exception handling, and more, use the @RepositoryRestController annotation ...

If you’re NOT interested in entity-specific operations but still want to build custom operations underneath basePath, such as Spring MVC views, resources, etc. use @BasePathAwareController.

So try to use @BasePathAwareController instead of @RepositoryRestController.

Community
  • 1
  • 1
Cepr0
  • 28,144
  • 8
  • 75
  • 101