The front-end request enters the back-end controller and reports an error [cannot serialize instance of ` Java. Lang. string ` out of start_object token]. From the error information, it is a JSON parsing error. Compare the content sent by the front-end request and the parameters received by the back-end controller to find the problem.
Content sent by the front end:
api_save(JSON.stringify({ po: this.form })).then(response => { if (response.code === 200) { this.$message.success('success to save') this.$emit('saved') } }).catch(() => { this.$message.error('failed to save') })
Parameters received by the back-end controller:
@PostMapping("/save") public Return<?> save(@RequestBody Map<String, String> paramMap) { try { service.save(JSON.parseObject(paramMap.get("po"), ProgEbs.class)); } catch (Exception e) { e.printStackTrace(); } return Return.success("save successfully"); }
After comparison, it is found that the front-end sending request is an object and the back-end controller receiving parameters are strings. Therefore, there is an error in JSON parsing at the back-end of the controller. At this time, just adjust the front-end sending request content to JSON strings or the back-end controller receiving parameters to object objects.
The former is used here:
api_save(JSON.stringify({ po: JSON.stringify(this.form) })).then(response => { if (response.code === 200) { this.$message.success('save successfully') this.$emit('saved') } }).catch(() => { this.$message.error('failed to save') })
This solves the problem of error reporting, and the back-end controller can receive parameters normally.
Similar Posts:
- [Solved] react native TypeError: Network request failed Unable to symbolicate stack trace: The stack is null
- How to Solve Error: Request failed with status code 500
- 405 error reporting in Web Development
- [Solved] Vue Axios error: TypeError: Cannot set property ‘tableData‘ of undefined
- Can not deserialize instance of java.lang.String out of START_OBJECT token
- Server returned HTTP response code: 500 for URL xxxxxxxxxxxxx
- Ajax “SyntaxError: missing ; before statement” [How to Solve]
- How to Solve Error: Unexpected token o in JSON at position 1
- Unity – JSON array deserialization