java - Optional Joda DateTime type field with JSR 303 Validation and Spring converter -



java - Optional Joda DateTime type field with JSR 303 Validation and Spring converter -

i have custom parameter converter & jackson mapper handle joda datetime on spring controllers input.

the problem is, server gives 400 bad request if date given in bad format, because of illegalargumentexception thrown joda formatter during conversion.

i create converter homecoming null on failing conversion (user typed bad date pattern), give me null in 2 situations:

user left field blank (which ok in optional field) user provided date in wrong format (never ok)

how differentiate scenerios "allow null (empty field), if not empty, check date format"?

background: field represented in pojo datetime , received in @controller @requestbody @valid becaus ajax-posted.

form pojo:

class myform { @notempty private string name; private datetime expireon; // joda, optional won't bad-format null. // getters, setters }

i think should utilize @scriptassert next :

@scriptassert(lang = "javascript", script = "_this.validateexpireon(_this.expireon)") public class myform{ public boolean validateexpireon(object obj){ // here check expireon object if null or not , if not null check date format // method should homecoming boolean if valid or not valid } private datetime expireon; }

hope helps .

java spring spring-mvc jodatime bean-validation

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -