-->
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.  [ 4 posts ] 
Author Message
 Post subject: What is the point of ".<collection element>"?
PostPosted: Tue Jun 13, 2017 2:18 pm 
Regular
Regular

Joined: Mon Aug 07, 2006 6:22 pm
Posts: 67
I'm implementing some "Type argument constraints" validators, and I noticed that the doc (and my prototype) has a Property Path value ending with ".<collection element".

What information does that provide that isn't implicitly obvious from the "listname[index]" that comes immediately before it?


Top
 Profile  
 
 Post subject: Re: What is the point of ".<collection element>"?
PostPosted: Wed Jun 14, 2017 3:25 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
This node name is chosen to indicate that the violation relates to a constraint declared on the type argument of a generic container, which lets you tell it apart e.g. from a constraint on a property of that container element. One probably could achieve the same with the name being null for the container element constraint case, but we favored the more explicit approach.

Note that in Bean Validation 2.0 / Hibernate Validator 6 there'll be a new node type (CONTAINER_ELEMENT), the node names will be standardized and there'll also be two new members on the relevant Node subtypes, getContainerClass() and getTypeArgumentIndex(), providing all the information to identify the location of the violated constraint.

If you look into using constraints on container element constraints, I'd recommend to try and use HV 6.0 as semantics have been clarified and partly changed in the course of adding this functionality to the specification. E.g. you can now have constraints on nested containers, too: Map<String, List<@Size(min=1) String>>.

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


Top
 Profile  
 
 Post subject: Re: What is the point of ".<collection element>"?
PostPosted: Wed Jun 14, 2017 3:12 pm 
Regular
Regular

Joined: Mon Aug 07, 2006 6:22 pm
Posts: 67
Gunnar wrote:
This node name is chosen to indicate that the violation relates to a constraint declared on the type argument of a generic container, which lets you tell it apart e.g. from a constraint on a property of that container element. One probably could achieve the same with the name being null for the container element constraint case, but we favored the more explicit approach.


It seems completely unambiguous to just end the property path with "collectionproperty[index]". In my code that uses the property path to render an error message, I'm specifically removing that string.

Gunnar wrote:
Note that in Bean Validation 2.0 / Hibernate Validator 6 there'll be a new node type (CONTAINER_ELEMENT), the node names will be standardized and there'll also be two new members on the relevant Node subtypes, getContainerClass() and getTypeArgumentIndex(), providing all the information to identify the location of the violated constraint.

If you look into using constraints on container element constraints, I'd recommend to try and use HV 6.0 as semantics have been clarified and partly changed in the course of adding this functionality to the specification. E.g. you can now have constraints on nested containers, too: Map<String, List<@Size(min=1) String>>.


Noted. I'll clearly have some porting work when/if we upgrade.


Top
 Profile  
 
 Post subject: Re: What is the point of ".<collection element>"?
PostPosted: Thu Jun 15, 2017 3:02 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Code:
It seems completely unambiguous to just end the property path with "collectionproperty[index]"


You'd end up with the same string representation if a class-level constraint in the contained element was violated (e.g. a @ScriptAssert on Address, when validating @Valid List<Address>). In BV 2.0 it'll be possible to put constraints to the values and keys of maps (or any type argument really), then the name further helps to identify the location.

_________________
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.  [ 4 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.