Spring REST input validation
<p>I'm writing a REST service using Spring Boot and JPA. I need to be able to validate some of the input fields and I want to ensure I'm using a proper pattern for doing so.</p>

<p>Let's assume I have the following model and I also have no control over the model:</p>

<pre><code>{
  "company"   : "ACME"
  "record_id" : "ACME-123"
  "pin"       : "12345"
  "company_name" : ""
  "record_type"  : 0
  "acl"          : ['View','Modify']
  "language"     : "E"
}
</code></pre>

<p>The things I need to do are:</p>

<ol>
<li>Ensure the value is not empty - This seems simple enough using the @NotEmpty annotation and I can pass a message.</li>
<li>Ensure the value is part of a valid list of values - The example here is the language property in the model above. I want the value to be either E,F or S. This seems possible using a custom annotation (eg @ValidValue({"E","F","S"})) but is there a better/"Springy" way to do this?</li>
<li>Ensure the values in a list are part of a valid list of values - The example here is the acl property. Again this seems possible with a custom annotation like @ValidListValues({"View", "Modify", "Delete", "Hide"}) but same question as above.</li>
<li>Set a default value - From what I read, custom validator annotations are only able to validate and not modify. I would like to do something like @DefaultValue(value=5) if the value is null. Is this possible? More on this below.</li>
<li>Set a default value to the return of a static method - For example if the pin field in model above isn't set, I want to set it to something like Util.getRandomDigitsAsString(5).</li>
<li>Use values from another property - I would like to validate that one property contains the string from another property. Using the example model, I want to ensure that record_id starts with company.</li>
</ol>

<p>I have this setup in what I believe is a standard way with the controller -> service -> DTO -> DAO -> Model. Another option I was thinking about was creating a method in the validateCreate() that would go through all of the items above and throw an exception if needed.</p>

<p>Thanks.</p>