0

I have the following bean class which is submitted from jsp form. And i need to validate it before saving to DB. But i want to ignore the collection field from form validation as it returns null from form always. I can remove that field altogether, but i am using this same bean class for some other scenario where i need collection in this bean. So is there any annotation or way to ignore the collection field from validating?

@Setter
@Getter    
public class ProvGroup {
        private long provGrpId; 
        @NotNull(message = "This field is required.")
        @NotEmpty(message = "This field is required.")
        @NotBlank(message = "This field is required.")
        private String provGrpName;
        private String description;  
        @NotNull(message = "This field is required.")
        @NotEmpty(message = "Add at least one provider to table.")
        private String provGrpProvs;
        private List<Provider> providers;   <--- I need to ignore this from validation
    }
Mohan
  • 699
  • 1
  • 11
  • 27
  • it's not annotated for Validation - are you getting any errors because it's null? – dimitrisli Dec 15 '16 at 16:47
  • Yes, below is the error message. Failed to convert property value of type [java.lang.String] to required type [java.util.List] for property 'providers'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.prov.model.Provider] for property 'providers[0]': no matching editors or conversion strategy found – Mohan Dec 15 '16 at 17:20
  • 1
    It is because you're sending bad/incorrect data for providers,i.e., an array of String. Either remove that from the request or change the type of providers field – Pallav Jha Dec 15 '16 at 17:51
  • As i mentioned above i am using the same bean for other scenario as well. So i cannot remove that or change the type of field. Is there any option to ignore that specific collection from validation? – Mohan Dec 15 '16 at 18:05
  • 3
    It has nothing to do with Validation. It is because you are sending in the form a property "providers" that Spring cannot convert to a List. – Alan Hay Dec 15 '16 at 18:23
  • The error wasn't raised beacause of validation. Bean validator ignores fields that wasn't annotated with constraints. Like ObiWan-PallavJha and Alan Hay said it is caused by incorrect request. – Jakub Ch. Dec 15 '16 at 18:24

0 Answers0