'Getting HttpMessageNotReadableException for Postman POST JSON input but records are not saving. Employee One-to-Many mapping for address
w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected character ('{' (code 123)): was expecting comma to separate Array entries; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('{' (code 123)): was expecting comma to separate Array entries at [Source: (PushbackInputStream); line: 10, column: 14]]
JSON is here and it's correct - Employee One-to-Many Mapping with employeeAddress
{
"name": "muhassin",
"designation": "software engineer",
"employeeAddress": [{
"city": "chennai",
"state": "Tamilnadu",
"country": "India"
}, {
"city": "mumbai",
"state": "Maharashtra",
"country": "India"
}]
}
Employee table (name, designation) record saved with empty entries for all the properties and employeeAddress table is not saving any records and getting null values for both these entities inside the java controller
//Creating a new Employee
@PostMapping("/employee/create")
public Employee createEmployee(@RequestBody Employee employee) {
return this.employeeRepo.save(employee);
}
Solution 1:[1]
Issue solved. The reason why we are getting the null values for entities properties inside the java controller was setter and getter methods are not added. Once added issue solved and record saved successfully.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Muhassin Musthafa A |
