0

I have a very simple application where I get POST request and save the JSON request to database.Here is my Entity object

@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "PRODUCT_TBL")
@Entity
public class Product {
    @Id
    @GeneratedValue
    private long id;
    private String name;
    private int quantity;
    private  double price;
}

Here is my controller

@RestController
public class ProductController {
    @Autowired
    ProductService productService;
    @PostMapping(value = "/save",consumes = MediaType.APPLICATION_JSON_VALUE)
    public Product saveProduct(@RequestBody Product product){
        System.out.println(product);//check whether properties are binded properly
        return productService.saveProduct(product);
    }
}

Here is my sample post request

{
 
  "name":"moto",
  "quantity":5,
  "price":50.00
}

But whenever I am seeing the logs, they are binding to default values

Product{name='null', quantity=0, price=0.0}

1 Answers1

1

I also faced a similar issue in the past. In my case problem was with lombok. I forgot to add annotationProcessor dependency along with lombok. Make sure to add appropriate dependency of lombok and annotationProcessor.This post might help you in adding right dependencies