• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Spring REST Validation

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I need to validate a simple JSON-Object, which comes in the body of a HTTP-request.
This is the spring controller with the relevant methods. The addEmployee() method works fine, the updateEmployee() method only works fine when the JSON in the request is valid. When the JSON is not valid does not get called at all


This is the dto-object:




That's how I do the request:


The 'content type'-header is set to application/json in both requests, the only difference in both calls is the URL and the http-method. When i cut the firstname to a length < 45 also updateEmployee() works fine.

I hope someone can help me with this,

thanks in advance,
Michael
 
Bartender
Posts: 15743
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what's the response you get from the server after sending the request?
 
Michael Oberleitner
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The response is 400 Bad Request



 
Stephan van Hulst
Bartender
Posts: 15743
368
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The binding result must come immediately after the validated parameter.
 
Michael Oberleitner
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks you very much Stephan!
I did not know this.
reply
    Bookmark Topic Watch Topic
  • New Topic