title: How to validate the incoming invalid XML @RequestBody with the Java Bean class
body: <p>I have a xml java bean class <code>Data</code> annotated with all the required xml annotations. Now when i try to post a xml request using postman with the correct xml format it works fine in the controller post method. But when i purposely add an extra xml tag (for testing invalid format) say <code>&lt;blabla&gt;&lt;/blabla&gt;</code> in postman and post it then again the controller does not throws any error and the code is working fine. Also the validator.validate() method also does not throws any error. I want to validate the invalid xml format against the Java Bean class.</p>
  <p>Controller method:
  <code>public DataRes ekycRequest(@RequestBody Data data) </code></p>
  <p>Note - Marshalling and Unmarshalling is the later process in the controller method.</p>
  <p><strong>Scenario 1:</strong>
  There is a DTO xml bean class (Data.java) annotated with all xml annotations and has 3 fields name, age, location. Now when i try to post a xml with the correct format i.e with three xml tags it is mapped in the controller <code>(@RequestBody Data data)</code> and no error.</p>
  <p><strong>Scenario 2:</strong>
  But when i try to add an additional tag purposely to test invalid xml format say  and post the xml request the <code>(@RequestBody Data data)</code> does not throws any error. I need a solution for this. It must throw error.</p>
  <p><strong>Scenario 3:</strong>
  When i try to avoid one tag and post xml with 2 tags i.e. invalid format then <code>(@ResponseBody Data data)</code> throws error which is what is needed in the above case i.e. scenario 2 also.</p>
  <p>Like in Hibernate DTO bean class (annotated with @Entity) we use @Valid annotation in controller argument to validate the incoming data.
  In the similar manner is there similar approach wfor the xml annotated beans class.</p>