title: javax.validation: Constraint to validate a string length in bytes
body: <p>I'm using <code>javax.validation</code> to validate some bean fields' values.</p>
  
  <p>This is what I use normally:</p>
  
  <pre><code>public class Market {
  
      @NotNull
      @Size(max=4)
      private String marketCode;
  
      @Digits(integer=4, fraction=0)
      private Integer stalls;
  
      // getters/setters
  }
  </code></pre>
  
  <p>This will make sure that every <code>Market</code> instance has a market code with a maximum length of <code>4</code> characters and a number of stall with a maximum of 4 integer digits and 0 decimal digits.</p>
  
  <p>Now, I use this bean to load/store data from/to DB.</p>
  
  <p>In the DB I have table <code>Markets</code> defined like this:</p>
  
  <pre><code>CREATE TABLE MARKETS (
      MARKET_CODE VARCHAR2(4 BYTE) NOT NULL,
      STALLS NUMBER(4,0)
  )
  </code></pre>
  
  <p>As you can see, I have <code>MARKET_CODE</code> which can be at most 4 <em>bytes</em> long. The <code>@Size</code> annotation will check if the string is at most 4 <em>characters</em> long, which is wrong.</p>
  
  <p>So, the question is: is there an annotation like <code>@Size</code> that will check for the string bytes instead of the characters?</p>