spring-web

Spring RestTemplate and generic types ParameterizedTypeReference collections like List<T>

天大地大妈咪最大 提交于 2019-12-29 05:41:06
问题 An Abstract controller class requires List of objects from REST. While using Spring RestTemplate its not mapping it to required class instead it returns Linked HashMAp public List<T> restFindAll() { RestTemplate restTemplate = RestClient.build().restTemplate(); ParameterizedTypeReference<List<T>> parameterizedTypeReference = new ParameterizedTypeReference<List<T>>(){}; String uri= BASE_URI +"/"+ getPath(); ResponseEntity<List<T>> exchange = restTemplate.exchange(uri, HttpMethod.GET, null

Can I use @Requestparam annotation for a Post request?

筅森魡賤 提交于 2019-12-28 12:31:33
问题 I have this controller method: @PostMapping( value = "/createleave", params = {"start","end","hours","username"}) public void createLeave(@RequestParam(value = "start") String start, @RequestParam(value = "end") String end, @RequestParam(value = "hours") String hours, @RequestParam(value = "username") String username){ System.out.println("Entering createLeave " + start + " " + end + " " + hours + " " + username); LeaveQuery newLeaveQuery = new LeaveQuery(); Account account = accountRepository

Can I use @Requestparam annotation for a Post request?

☆樱花仙子☆ 提交于 2019-12-28 12:31:29
问题 I have this controller method: @PostMapping( value = "/createleave", params = {"start","end","hours","username"}) public void createLeave(@RequestParam(value = "start") String start, @RequestParam(value = "end") String end, @RequestParam(value = "hours") String hours, @RequestParam(value = "username") String username){ System.out.println("Entering createLeave " + start + " " + end + " " + hours + " " + username); LeaveQuery newLeaveQuery = new LeaveQuery(); Account account = accountRepository

Spring Getting Started Guide “Accessing JPA Data with REST” not working

安稳与你 提交于 2019-12-25 07:14:28
问题 I'm learning Spring using the Getting Started Guides. Right now I'm trying to complete "Accessing JPA Data with REST" guide but my code didn't work, so I tried the "complete" version, and it doesn't work too. So far everytime I import content using Spring Tool Suite (STS), the "complete" version executes as expected, according to the description in the guides, but it's not happening right now. The guide instructs me to run the Project as a "Spring Boot App", then to execute a curl command to

Spring WebFlux - Content type 'application/xml' not supported for bodyType=org.springframework.web.multipart.MultipartFile

狂风中的少年 提交于 2019-12-24 07:30:37
问题 I am using spring-webflux and want to upload files .... everything works great with just spring-web but when it comes to webflux i have not a clue what's wrong . Be careful in the difference ... i am using : <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> So let's say we have the below @RestController , for Spring Web it works like charm: @PostMapping(value = "/uploadFile") public Response uploadFile(@RequestParam(

Spring tries to deserialize to LinkedHashMap instead of POJO

心已入冬 提交于 2019-12-23 07:11:57
问题 I'm creating a simple rest controller with Spring Boot and the Web dependency. I'm trying to deserialize a JSON body to a test POJO with only 3 fields, but when I attempt to make a POST request, the server responds with a 500 error and the error I get in the console is: .w.s.m.s.DefaultHandlerExceptionResolver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class java.util.LinkedHashMap All of the

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

ぃ、小莉子 提交于 2019-12-22 18:35:24
问题 I got the following @RestController inside a spring boot application : @Data @RestController public class Hello { @Autowired private ResturantExpensesRepo repo; @RequestMapping(value = "/expenses/restaurants",method = RequestMethod.POST,consumes =MediaType.APPLICATION_JSON_VALUE , headers = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public void hello(@RequestBody ResturantExpenseDto dto) { Logger logger = LoggerFactory.getLogger("a"); logger.info("got a request"); ResturantExpenseEntity

Spring RestTemplate POST Request with URL encoded data

余生颓废 提交于 2019-12-22 03:18:25
问题 I'm new to Spring and trying to do a rest request with RestTemplate. The Java code should do the same as below curl command: curl --data "name=feature&color=#5843AD" --header "PRIVATE-TOKEN: xyz" "https://someserver.com/api/v3/projects/1/labels" But the server rejects the RestTemplate with a 400 Bad Request RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.add("PRIVATE-TOKEN", "xyz"); HttpEntity<String> entity = new HttpEntity<String>("name

Spring REST Controller returns JSON with empty data [closed]

╄→尐↘猪︶ㄣ 提交于 2019-12-22 02:34:05
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I have a simple Spring Boot web application. I'm trying to receive some data from server. The Controller returns a collection, but the browser receives empty JSON - the number of curly brackets is equals to the number of objects from server, but its content is empty. @RestController public class

Spring Rest Controller: how to selectively switch off validation

时光怂恿深爱的人放手 提交于 2019-12-18 07:48:21
问题 In my controller I have a method for creating an entity import javax.validation.Valid; ... @RestController public class Controller { @RequestMapping(method = RequestMethod.POST) public ResponseEntity<?> create(@Valid @RequestBody RequestDTO requestDTO) { ... with import org.hibernate.validator.constraints.NotEmpty; ... public class RequestDTO @NotEmpty // (1) private String field1; //other fields, getters and setters. I want to add a controller method update(@Valid @RequestBody RequestDTO