Why I am getting NULL Object as response when sending JSON Object to SpringBoot application from POSTMAN?

Viewed 35

NOTE: When I am using Lombak then only I am getting Null Object as a response to the PostMan. If I use the manually typed getter and setter method I am getting actual data as the response to the Postman. Entity: This is my Entity Class

package com.example.demo.CitizenService.Entity;  
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; 
import javax.persistence.Id;  
import lombok.AllArgsConstructor; 
import lombok.Data; 
import  lombok.Getter; 
import lombok.NoArgsConstructor; 
import lombok.Setter;

 @Entity                                                              
 @Data                                                                 
 @NoArgsConstructor                                                    
 @AllArgsConstructor                                                   
 @Setter 
 @Getter  
 public class Citizen {
    @Id                                         
     @GeneratedValue(strategy=GenerationType.AUTO)                                                   
     private int id;    
     @Column                                                                                
     private String name;               
     @Column    
     private int vaccinationId;                                                         }

Repository: This is my Repository class

 package com.example.demo.CitizenService.repositories;
 import java.util.List;
 import org.springframework.data.jpa.repository.JpaRepository;
 import com.example.demo.CitizenService.Entity.Citizen;
 
 public interface CitizenRepos extends JpaRepository<Citizen,Integer> 
 {
 
     public List<Citizen> findByvaccinationId(Integer id);       
 }

Controller: This is my Controller

  package com.example.demo.CitizenService.Controller;
  import java.util.List; 
  import org.springframework.beans.factory.annotation.Autowired; 
  import org.springframework.http.HttpStatus; 
  import org.springframework.http.ResponseEntity; 
  import org.springframework.web.bind.annotation.RequestMapping; 
  import org.springframework.web.bind.annotation.RestController; 
  import com.example.demo.CitizenService.Entity.Citizen;   
  import com.example.demo.CitizenService.repositories.CitizenRepos;
  import org.springframework.web.bind.annotation.PathVariable;  
  import org.springframework.web.bind.annotation.PostMapping; 
  import org.springframework.web.bind.annotation.RequestBody;
 
@RestController @RequestMapping("/citizen") public class
  CitizenController {
 
    @Autowired   private CitizenRepos repo;
    @PostMapping("/add") public ResponseEntity<Citizen> 
     addCitizen(@RequestBody Citizen citizen)    
           {         
         System.out.println("I am Citizen Method");         
         Citizen citizen1 = repo.save(citizen);         
         return new ResponseEntity<>(citizen1, HttpStatus.OK);  
           }
 }
````````````````````````````````````
 properties file: application.properties
````````````````````````
server.port=8081
spring.datasource.url=jdbc:mysql://localhost:3306/citizendb
spring.datasource.username=root
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.application.name=CITIZEN-SERVICE
 
[Please find the attached Image where I highlighted in yellow color whivh is the output I am getting]


             


  [1]: https://i.stack.imgur.com/thlH7.png
0 Answers
Related