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
5
votes
4 answers

@RequestBody not mapping JSON to Java Object - Spring Boot

I am unable to convert my JSON from post's method body into my POJO, with @RequestBody inside my controller class. I debugged the error and I saw that certain fields were mapped and others were not. Like this (POJO): name: null, typeOfPlan: null,…
Compiler v2
  • 3,509
  • 10
  • 31
  • 55
5
votes
2 answers

Spring ControllerAdvice - Fail to override handleHttpRequestMethodNotSupported() in ResponseEntityExceptionHandler

Here's a few facts for the situation that I'm currently facing I have recently built a RestControllerAdvice with variousExceptionHandler as a global exception handler for my Spring RestController. As I would like to return my customized response…
jackycflau
  • 1,101
  • 1
  • 13
  • 33
5
votes
1 answer

Spring MVC RequestMapping not working on RestController

I want to have a RestController-class with the base-mapping "/user" (so the different functions will have paths like "/user/add", "/user/remove" etc or use POST/GET etc) This is the part that I don't understand and can't get to…
Juliette
  • 966
  • 16
  • 35
5
votes
3 answers

How to validate non-required RequestParam is not blank?

I'm using validators in my spring controllers. If @RequestParam is required there is no problem, i can check String with @NotBlank. But if @RequestParam is optional, i can't use it with @NotBlank, because this parameter is optional and sometimes…
Edward D. Wilson
  • 351
  • 1
  • 4
  • 11
5
votes
4 answers

Spring REST Controller is not responding to Angular request

I have an app to create server certificate requests, just as if one were using java keytool or something. I'm trying to return the created certificate request and the key in a zip file, but for the life of me, I can't get my REST controller to…
CNDyson
  • 1,687
  • 7
  • 28
  • 63
5
votes
5 answers

Get XML in plain text

I have this endpoint for Spring Rest API: @PostMapping(value = "/v1/", consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_XML_VALUE, …
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
5
votes
2 answers

The Spring validation @NotNull does not validate

I’m trying to validate a POST request using Spring Validator. This is the Object I’m trying to validate: @Validated public class Request implements Serializable { private static final long serialVersionUID = 1L; private Long id1; …
blueSky
  • 649
  • 5
  • 13
  • 31
5
votes
1 answer

Spring Boot Rest API filter not invoked

I want to implement filter on my Spring Boot Rest API project but some how my filter not invoked. I have added below implementation for that. public class AutorizationFilter implements Filter{ Logger log =…
5
votes
4 answers

Supporting application/json and application/x-www-form-urlencoded simultaneously from Spring's rest controller

Am writing a REST endpoint which needs to support both application/x-www-form-urlencoded and application/json as request body simultaneously. I have made below configuration, @RequestMapping(method = RequestMethod.POST, produces = {…
Anshul Sharma
  • 81
  • 1
  • 7
5
votes
2 answers

@RestControllerAdvice and @ControllerAdvice together

I have an Spring MVC application which has @Controller s and @RestController s. I was thinking that: When I have some Exception at my @Controller, It gonna be handled by my @ControllerAdvice and when I have some Exception at my @RestController, It…
Andre
  • 652
  • 2
  • 7
  • 23
5
votes
3 answers

Spring - RestController annotation does not catch request

I don't understand why If I use RestController annotation to declare a class as service, like this: @RestController("/registration") public class RegistrationService { @RequestMapping(value="/", produces="application/json") …
Dave
  • 1,428
  • 4
  • 31
  • 49
5
votes
1 answer

unit test spring controller with WebTestClient and ControllerAdvice

I'm trying to unit test my controller and the specific case which is : my service return a Mono.Empty, I throw a NotFoundException and I wan't to make sure I'm getting a 404 exception here's my controller : @GetMapping(path = "/{id}") public…
Seb
  • 3,602
  • 8
  • 36
  • 52
5
votes
1 answer

Spring RestController POST 400 Bad Request

I have a Spring RestController that any attempt to post to it returns 400 Bad Request despite seeing the correct data being sent in Chrome Developer Tools. The @Valid annotation is kicking it out because the ParameterDTO object is not being…
greyfox
  • 6,426
  • 23
  • 68
  • 114
5
votes
0 answers

Implementing RequestMethod.PATCH in Spring RestController

I am creating a Rest API for a MongoDB database using MongoRepository. I want to create an endpoint that uses "RequestMethod.PATCH" and implements the "PATCH" functionality: delta update with fields provided in the @RequestBody. The functionality…
5
votes
2 answers

How to map a path variable to an entity in spring-rest

I got some REST endpoint in Spring-RS which use an entity id as path variable. Most of the time, the first thing the method is doing is retrieving the entity using the id. Is there a way to automatically map the id to the entity, having only the…
Teocali
  • 2,725
  • 2
  • 23
  • 39