Struggling to send a JSON to my API, I've tried various solutions but still can't figure out what's going wrong. I'm stuck on this post call function:
@PostMapping(path = "ts/sts")
public void saveTestStep(@RequestBody TestStepDTO testStepDTO){
TestStep testStep = new TestStep(testStepDTO.getTestCaseId(),
testStepDTO.getStepNumber(),
testStepDTO.getDescription(),
testStepDTO.getTestdata(),
testStepDTO.getPrerequisite(),
testStepDTO.getResult());
TestStepService testStepService = new TestStepService();
testStepService.save(testStep);
}
Here is the JavaScript code I use to make the call:
for(i=0;i<prerequisites.length;i++){
b = i+1;
$.ajax({
url: 'http://localhost:8080/ts/sts',
dataType: 'json',
type: 'post',
contentType: 'application/json',
data: [{ "result": result[i], "stepNumber": b, "description": description[i],"testCaseId": 1 , "testdata": testdata[i], "prerequisite": prerequisites[i]}] ,
processData: false,
success: function( data, textStatus, jQxhr ){
$('#response pre').html( JSON.stringify( data ) );
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( errorThrown );
console.log("testcaseid: " + testcaseid);
}
});
}
Showing here is the DTO class structure:
public class TestStepDTO {
@NotBlank
private Integer testCaseId;
@NotBlank
private Integer stepNumber;
@NotBlank
private String description;
@NotBlank
private String result;
@NotBlank
private String testdata;
@NotBlank
private String prerequisite;
// Getters and setters for each field
}
But upon running, I encounter this issue:
2021-04-01 18:49:06.043 WARN 28296 --- [io-8080-exec-10] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `b...
If anyone sees or knows where I might be going wrong in this process, any help would be greatly appreciated!