Spring Boot: Prevent decoding for @RequestParam

Aracos

I have a Spring-Boot (1.5.3) application running on a Tomcat 8.5. Within it, i have a RestController with a single parameter.

This parameter is decoded automatically - which is fine for all other controllers within my application, but for this one, i need the raw request data, since they will be used within another request. Please note that i wold like to only disable the auto-decoding for this Controller/request and keep the normal behaviour everywhere else.

@RestController
@RequestMapping("/rest/test")
public class TestController {

  @RequestMapping("/test")
  public ResponseEntity<String> test(@RequestParam final String test){
    return ResponseEntity.ok("Requested: " + test);
  }
}

Now, if i send access it with

curl localhost/rest/test/test?test=%C3%B6%20%C3%A4

I receive the output:

Requested: ö ä

I would like to have

Requested: %C3%B6%20%C3%A4

Any Ideas?

Daniel Olszewski

If you need this behavior only in a single place, you can encode the parameter back to the original form using the standard Java URLEncoder inside of the controller body:

@RequestMapping("/test")
public ResponseEntity<String> test(@RequestParam final String test) {
  String encodedParam = URLEncoder.encode(test, "UTF-8");
  return ResponseEntity.ok("Requested: " + encodedParam);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring 3.2 MVC @RequestParam unexpected decoding

Spring boot REST: cannot test validation of @RequestParam

Spring boot API call with multiple @RequestParam

Spring boot http POST @RequestParam multiple parameters

Spring Boot: Get Object from @RequestParam("id")

Send RequestParam to Spring Boot Server in Axios

Spring Boot REST @RequestParam not being Validated

Requestparam as object in spring boot rest mapping

How to use @JsonDeserialize for @RequestParam params in Spring Boot

How to pass encrypted value in @Requestparam java spring boot

Feign Client with Spring Boot: RequestParam.value() was empty on parameter 0

Spring Boot Validate JSON Mapped via ObjectMapper GET @RequestParam

Spring Boot non-required @RequestParam with String Data Type

Password encoding and decoding using Spring Security, Spring Boot and MongoDB

How to prevent spring boot app from starting

Prevent Spring Boot from printing logs to console

Is there a way to prevent bean overriding with Spring Boot?

Spring Boot: Prevent persisting field declared in superclass

Prevent Spring Boot from registering a servlet filter

Spring Boot prevent empty file generation on error

@RequestParam with Optional Spring REST

Spring's @RequestParam with Enum

Spring's @RequestParam with Enum

spring validation for requestparam not working

Spring File Upload with RequestParam

Spring @RequestParam Date Formatting

Sending % through @RequestParam in Spring

Spring MVC @RequestParam and @SessionAttribute

Spring Boot POST mapping with a validated form bean *and* a RequestParam gives 405 error on invalid form

TOP Ranking

HotTag

Archive