Creating a rest API using Java Spring and would like to get the input in Map format, but get the below error. Does anyone know what is causing this exception to happen?
Resources been looked (could not resolve the issue):
http://www.java2s.com/Tutorials/Java/Spring/0140__Spring_Map_Properties.htm
Spring MVC populate @RequestParam Map<String, String>
https://www.baeldung.com/spring-date-parameters
@RequestMapping("/api")
public interface ApiController {
@GetMapping("/submitJob")
JobSubmitResultDTO submitJob(@RequestBody JobSubmitRequestDTO request);
}
@Data
public class JobSubmitRequestDTO {
Map<String,Object> paramsMap = new HashMap<String,Object>();
}
@Data
public class JobSubmitResultDTO {
String jobID;
String message;
}
@RestController
public class ApiController implements ApiController {
@Override
public JobSubmitResultDTO submitJob(JobSubmitRequestDTO request) {
//Create an instance of JobSubmitResultDTO
JobSubmitResultDTO response = new JobSubmitResultDTO();
return response; //return null values for now
}
}
URL: http://XXXXXXXXX:XXXXX/api/submitJob?paramsMap=%7B%7D
***passing {} -> %7B%7D or {'Age':12} would return the same error***
Error:
{
"timestamp": "2020-03-19T21:38:15.443+0000",
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.validation.BindException",
"errors": [
{
"codes": [
"typeMismatch.jobSubmitRequestDTO.paramsMap",
"typeMismatch.paramsMap",
"typeMismatch.java.util.Map",
"typeMismatch"
],
"arguments": [
{
"codes": [
"jobSubmitRequestDTO.paramsMap",
"paramsMap"
],
"arguments": null,
"defaultMessage": "paramsMap",
"code": "paramsMap"
}
],
"defaultMessage": "Failed to convert property value of type 'java.lang.String' to required type 'java.util.Map' for property 'paramsMap'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Map' for property 'paramsMap': no matching editors or conversion strategy found",
"objectName": "jobSubmitRequestDTO",
"field": "paramsMap",
"rejectedValue": "{}",
"bindingFailure": true,
"code": "typeMismatch"
}
],
"message": "Validation failed for object='jobSubmitRequestDTO'. Error count: 1",
"path": "/api/submitJob"
}