-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Payload interface and static declaration
PostPosted: Mon Aug 25, 2014 7:56 pm 
Newbie

Joined: Wed Jan 04, 2006 2:29 pm
Posts: 8
I've experimented a bit with the BV API and I'm quite happy with it but I find the way to pass back metadata along with the error a bit limiting, if payloads is an array of static classes that can lead to an explosion of classes, it would have been nice if simple static things like list of enums or strings or numbers would have been allowed as well.
Ex, I'd like to assign a specific error code to an validation exception which doesn't have anything to do with the error message but will be used programmatically?
Ex. @NotNull(message="my_custom_not_null_key", payload={"Code._12345"})


Top
 Profile  
 
 Post subject: Re: Payload interface and static declaration
PostPosted: Thu Aug 28, 2014 9:52 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

The problem is that one cannot design an annotation attribute such as payload() in a way that it can take an enum OR a String OR an int etc. Thus we went for the class-based approach.

In your case you may be able to use the message() property in a somewhat creative way by working with a defined format of messages; E.g. in the form "code#key" with "12345#my_custom_not_null_key" being one specific message. You could then implement a custom message interpolator (https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#section-custom-message-interpolation) which only considers the key part of the messages for interpolation, whereas the code part may be accessed by your other programmatic logic.

Hth,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.