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
23
votes
1 answer

Difference between @RestController and @RepositoryRestController

What is the typical use case code that shows the difference between those two annotations - meaning the @RestController and the @RepositoryRestController - ?
mCs
  • 2,591
  • 6
  • 39
  • 66
23
votes
6 answers

lost one day for a date

On client side, i use dd/MM/yyyy date format. The field use a twitter bootstrap 3 datetime picker (https://eonasdan.github.io/bootstrap-datetimepicker/) I enter via twitter bootstrap 3 datetime picker 24/07/2015 in my json i sent, i see: birthdate:…
robert trudel
  • 5,283
  • 17
  • 72
  • 124
23
votes
5 answers

Spring Rest Controller Return Specific Fields

I've been going through my head the best way to design a JSON API using Spring MVC. As we all know IO is expensive, and thus I don't want to make the client make several API calls to get what they need. However at the same time I don't necessarily…
greyfox
  • 6,426
  • 23
  • 68
  • 114
22
votes
1 answer

Spring throwing HttpMediaTypeNotAcceptableException: Could not find acceptable representation due to dot in url path

Final Edit So after researching this because the answer's didn't quite make since with what I was seeing, I found out that Spring does some weird stuff with extension matching. If I submit a request like this byNameOrAtlName/myStringHere.1 or this…
Zipper
  • 7,034
  • 8
  • 49
  • 66
21
votes
1 answer

How to Use Spring Boot's 'spring.jackson.date-format' Property?

According to the Current SpringBoot Reference Guide if I set the spring.jackson.date-format property, it will: Date format string or a fully-qualified date format class name. For instance 'yyyy-MM-dd HH:mm:ss'. However, it doesn't work this way…
peterl
  • 1,881
  • 4
  • 21
  • 34
19
votes
7 answers

Spring upload file size limit error

I am using Spring Boot and I can send images that are smaller than 1MB, but when I make a post request with a large image larger than 1MB I get this error: Maximum upload size exceeded; nested exception is…
Ryan Fasching
  • 449
  • 2
  • 11
  • 21
19
votes
2 answers

What type of exception to throw in Spring RestController when validation fails?

In a Spring RestController I have an input validation of the RequestBody simply by annotating the corresponding method parameter as @Valid or @Validated. Some other validations can only be performed after some processing of the incoming data. My…
Gregor
  • 2,917
  • 5
  • 28
  • 50
18
votes
4 answers

Content type 'text/plain;charset=UTF-8' not supported error in spring boot inside RestController class

I got the following @RestController inside a spring boot application : @Data @RestController public class Hello { @Autowired private ResturantExpensesRepo repo; @RequestMapping(value = "/expenses/restaurants",method =…
nadavgam
  • 2,014
  • 5
  • 20
  • 48
17
votes
12 answers

Spring File Upload - 'Required request part is not present'

I am trying to send POST request to my controller but cannot pass any parameter in any type unless I decide to use JSON. My goal is to pass a String and a file to my controller but I keep getting Required request part 'xxx' is not present…
Gokhan Celikkaya
  • 716
  • 1
  • 7
  • 17
17
votes
7 answers

Infinite loop with spring-boot in a one to many relation

In a rest application, I use spring boot with jpa. I have a class Lodger who have @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "lodger") private List referenceList; In my class Reference, i…
robert trudel
  • 5,283
  • 17
  • 72
  • 124
16
votes
2 answers

Spring Boot RestController, On Error Status Response Body, Message of Error is empty

On my Spring Boot RestController I want to pass a custom error message to the response body by throwing a custom exception. I was following the guide on https://dzone.com/articles/spring-rest-service-exception-handling-1 These are my code…
Hannes Roth
  • 163
  • 1
  • 1
  • 7
16
votes
4 answers

Caching in Spring 5 WebFlux

Are there any way to cache a Flux coming from WebClient in Spring 5? I tried this but is not caching anything. @RestController @SpringBootApplication @EnableCaching public class GatewayApplication { @PostMapping(value ="/test", produces =…
Esteban S
  • 1,859
  • 5
  • 22
  • 43
16
votes
2 answers

Can spring map POST parameters by a way other than @RequestBody

I am using @RestControllers with an application where all requests are POST requests ... As I learned from this post , you can't map individual post parameters to individual method arguments, rather you need to wrap all the parameters in an object…
osama yaccoub
  • 1,884
  • 2
  • 17
  • 47
16
votes
3 answers

How to get List from Page in Spring Data REST

I am using JPARespository for all my CRUD operation. Recently I wanted to implement sorting, so I went ahead with Pagable. The problem is, I want the repository methods to return List objects, I use them in my service layer. How can I achieve this,…
16
votes
1 answer

Using Spring @RestController to handle HTTP GET with ZonedDateTime parameters

I'm creating an endpoint that will receive dates to do some filtering in the server side. The code looks like this: @RequestMapping( value = "/test", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE,…
Andrés Soto
  • 954
  • 1
  • 10
  • 20