I get NullPointerException when validating object. I send to controller dto, and when validating it. I cant understan where is the problem because product that goes into validate method is not null, Validator code :
@Override
public void validate(Object o, Errors errors) {
Product product = (Product) o;
if (product.getTitle().isEmpty() || product.getTitle() == null) {
errors.rejectValue("title", "product.title", "Product title cant be empty");
}
if (product.getDescription().isEmpty() || product.getDescription() == null) {
errors.rejectValue("description", "product.description", "Product description cant be empty");
}
if (product.getPrice().isNaN() || product.getPrice()<=0 || product.getPrice() == null) {
errors.rejectValue("price", "product.price", "Product price is not valid");
}
if (product.getCategory()==null) {
errors.rejectValue("category", "product.category", "Product category is not valid");
}
}
and i get this
java.lang.NullPointerException com.shop.validator.ProductValidator.validate(ProductValidator.java:27) com.shop.controller.ProductController.createProduct(ProductController.java:82) com.shop.controller.ProductController$$FastClassBySpringCGLIB$$c0d382c4.invoke() org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)