Questions tagged [spring-restcontroller]

@RestController is Spring MVC's shortcut annotation for creating Rest Controllers. Use this tag for questions relating to the use of this annotation.

@RestController is an Spring annotation that is used to declare controllers where all @RequestMapping annotated methods assume @ResponseBody semantics by default.

Useful links:

1579 questions
3
votes
3 answers

How to nest @PathVariable in spring-rest?

I have a simple @RestController service that takes query parameters, and spring automatically parses them to an bean: @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/rest", method = RequestMethod.GET) public MyDTO getGiataHotel(@Valid…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
3
votes
2 answers

How to integrate Spring Rest with Apache Wicket web application

I have Apache Wiket + Spring web application that works without any issues . At present Spring used DI framework and to filter Mobile access . We are planning to use Spring Rest in our application , Can you advise me how do I do this in our…
csf
  • 529
  • 1
  • 4
  • 16
3
votes
3 answers

How to handle HttpMediaTypeNotAcceptableException by writing error content to the response body using exception handler annotation?

When a client request for a resource producing application/json content with Accept Header of application/xml. The request fails with HttpMediaTypeNotAcceptableException exception and is wrapped into error message body in the response entity object…
s7vr
  • 73,656
  • 11
  • 106
  • 127
3
votes
2 answers

How can I get a Spring @RestController to accept parameters in JSON format rather than www-form-urlencoded?

Using Spring 4.1.7 on JDK 1.8, I have an @RestController class that looks like this: @RestController public class ServiceAController { public static final Logger LOG = Logger.getLogger(ServiceAController.class); …
Jared
  • 25,520
  • 24
  • 79
  • 114
3
votes
1 answer

Spring MVC @RestController -> PUTting results in "400 Bad Request" no matter what I do

I have a Spring RestController which works great when I GET data from it, but when I try to PUT the very same data, I get a 400 Bad Request. Here is the simplest version of my controller that should still work (I left out the GET…
Kirby
  • 303
  • 2
  • 16
3
votes
1 answer

Rest Custom HTTP Message Converter Spring Boot 1.2.3

I want to create a custom of HttpMessageConverter using Rest, Json, Spring Boot 1.2.3 and Spring 4, However my custom HTTPMessageConverter its' never called. I have preformed the following steps : 1: Created a class that extends…
Kamal
  • 1,476
  • 1
  • 13
  • 21
2
votes
1 answer

Spring: REST-Controller cannot be found by SpringBootApplication

I'm building a Spring-REST-API with CRUD-functionality to create, read, update and delete books with a MongoDB-database. My project has the following structure: BackendBookLibraryApplication.java in main > java >…
2
votes
1 answer

Spring Boot API versioning using @RequestMapping

As far as I know, we can version our APIs for some reason e.g. there is a change needed for the current API but we also need to use it in its previous state. For this purpose, I generally use the following approach from start when building a…
Jack
  • 1
  • 21
  • 118
  • 236
2
votes
1 answer

How to handle different data type in Request - Spring

In a UserWithIdsRequest object public UserWithIdsRequest{ ... @XmlElementWrapper(name = "userIds") @XmlElement(name = "userId") private List userIds; ... } This object maps to body of get request. There is List of…
aman goyal
  • 191
  • 2
  • 14
2
votes
2 answers

spring/hibernate validation -> error message is not passed to caller?

I am using org.springframework.boot:spring-boot-starter-validation:2.7.0(which in turn uses hibernate validator) to validate user input to rest controller. I am using Spring Boot Web Starter (2.7.0) based project with @RestController annotation My…
2
votes
1 answer

Spring Boot: How to validate all parameters in a RestController

Say I have a @RestController with 10 methods, each of which takes one or more parameters. How can I tell Spring to validate each and every one of those parameters without annotating all of them with @Valid? I already tried annotating the whole class…
Markus Rohlof
  • 380
  • 3
  • 13
2
votes
1 answer

Applying custom runtime logic to JSON serialization in SpringBoot @RestController response

We are building an app that may produce hundreds of unique JSON payload structures from our streamlined object model and we want to avoid adding hundreds of POJOs to our Java codebase (1 per unique payload structure). We built a way to build, parse…
2
votes
2 answers

Spring Boot - expose endpoints only in Swagger UI but not via direct HTTP call

Is it possible to expose some selected endpoints only in Swagger UI, but make them unavailable at the server otherwise via direct HTTP call? There is @Operation(hidden=true) to not to expose the endpoint in Swagger UI but still have it available on…
Honza Zidek
  • 9,204
  • 4
  • 72
  • 118
2
votes
1 answer

PK string returns in Spring response

I am trying to return custom error message by using @ExceptionHandler but I receive extra junk value of PK in the response. I have attached the screen shot as well as code here in for any suggestion. Anyone can suggest here? Java…
2
votes
1 answer

What is the difference between returning void and ResponseEntity in Spring Boot RestController?

I wonder what the difference is between the return value of a Spring Boot RestController if void shall be returned? I can see do difference in a test in either way. It seems that even if I return void the HttpStatus.NO_CONTENT (204) is returned to…