Search code examples
spring-bootpostman

Postman return null values in response


I have created a simple Java spring boot API to add employees. I want to check to employee add endpoint. When I try with it in postman I am getting null values in response.

But its status is 200 and id auto-increment is also working fine.

enter image description here

Controller:

@RestController
@RequestMapping("/api/vi")
public class EmplyeeController {
  @PostMapping("/add")
    public Employee addEmployee(@RequestBody Employee employee) {
       return employeeRepository.save(employee);
    }
}

Repository:

@Repository
public interface EmployeeRepository extends JpaRepository<Employee, 
Long>{}

How can I solve this? This is my first spring boot application. I wish your help to solve this. Thank you.


Solution

  • You need to correct your payload as Spring bind your payload with Entity when it should have the same attribute but In your case you are using _ "underscore" in your payload and in Entity you are using camelCase so the solution would be updating the post payload and then it will work.

    {
       "emailAddress":"",
       "firstName":"",
       "lastName":""
    }