I am facing problem with postman.
I am trying to test a rest end point url using Postman. It is spring boot application.
Here, I am sending 9 parameters in request body to controller but controller receives only 6 parameters, rest three parameters controller receives as null. Due to this, I am getting jakarta.validation.ConstraintViolationException: because these parameters can’t be null.
Postman Image is –
Exception is –
jakarta.validation.ConstraintViolationException: Validation failed for classes [com.validate.validate_barcode.entity.Corporate] during persist time for groups [jakarta.validation.groups.Default, ]
List of constraint violations:[
ConstraintViolationImpl{interpolatedMessage='must not be null', propertyPath=spocMobile, rootBeanClass=class com.validate.validate_barcode.entity.Corporate, messageTemplate='{jakarta.validation.constraints.NotNull.message}'}
ConstraintViolationImpl{interpolatedMessage='must not be null', propertyPath=spocName, rootBeanClass=class com.validate.validate_barcode.entity.Corporate, messageTemplate='{jakarta.validation.constraints.NotNull.message}'}
ConstraintViolationImpl{interpolatedMessage='must not be null', propertyPath=spocEmail, rootBeanClass=class com.validate.validate_barcode.entity.Corporate, messageTemplate='{jakarta.validation.constraints.NotNull.message}'}
]
at org.hibernate.boot.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:151) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
at org.hibernate.boot.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:81) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]
Entity Class is
@Entity
@Table(name = "corporate")
public class Corporate extends Auditable<String>{
// Primary ID which increments automatically when new entry is added into the
// database
@Id
//@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
// @GenericGenerator(name = "native", strategy = "native")
int id;
// UCIC = Unique Corporate Identification Code
@Column(name = "ucic", length = 9)
@NotNull
private String ucic;
@Column(name = "corp_name")
@NotNull
private String corpName;
@Column(name = "category")
@NotNull
private String category;
@Column(name = "corp_email")
@NotNull
private String corpEmail;
@Column(name = "corp_mobile")
@NotNull
private String corpMobile;
@Column(name = "corp_address")
@NotNull
private String corpAddress;
@Column(name = "spoc_email")
@NotNull
private String spocEmail;
@Column(name = "spoc_name")
@NotNull
private String spocName;
@Column(name = "spoc_mobile")
@NotNull
private String spocMobile;
public Corporate() {
super();
}
//setter and Getter
}
And Controller Class is –
public class CorporateController {
// Annotation
@Autowired
private CorporateService corporatService;
// Save operation
//@PostMapping("/saveCorporate")
@RequestMapping(value = "/saveCorporate" , method = RequestMethod.POST, produces = "application/json")
public Corporate saveCorporate(@RequestBody Corporate corporate) {
System.out.println("Post Mapping - saveDepartment");
System.out.println(corporate.toString());
return corporatService.saveCorporate(corporate);
}
}
Can some one please help me on this?
Thanks.