Spring Validate List of Strings for non empty elements
<p>I have a model class which has list of Strings. The list can either be empty or have elements in it. If it has elements, those elements can not be empty. For an example suppose I have a class called QuestionPaper which has a list of questionIds each of which is a string.</p>

<pre><code>class QuestionPaper{
private List&lt;String&gt; questionIds;
....
}
</code></pre>

<p>The paper can have zero or more questions. But if it has questions, the id values can not be empty strings. I am writing a micro service using SpringBoot, Hibernate, JPA and Java. How can I do this validation. Any help is appreciated.</p>

<p>For an example we need to reject the following json input from a user.</p>

<pre><code>{ "examId": 1, "questionIds": [ "", " ", "10103" ] }
</code></pre>

<p>Is there any out of the box way of achieving this, or will I have to write a custom validator for this.</p>