Java Code Examples for javax.validation.Path.Node#getKey()
The following examples show how to use
javax.validation.Path.Node#getKey() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConstraintViolationExceptionMapper.java From crnk-framework with Apache License 2.0 | 5 votes |
private Object getNodeReference(Object element, Node node) { Integer index = node.getIndex(); Object key = node.getKey(); if (index != null) { appendSeparator(); appendSourcePointer(index); return ((List<?>) element).get(index); } else if (key != null) { appendSeparator(); appendSourcePointer(key); return ((Map<?, ?>) element).get(key); } else if (element instanceof Set && getValue(node) != null) { Object elementEntry = getValue(node); // since sets get translated to arrays, we do the same here // crnk-client allocates sets that preserver the order // of arrays List<Object> list = new ArrayList<>(); list.addAll((Set<?>) element); index = list.indexOf(elementEntry); appendSeparator(); appendSourcePointer(index); return getValue(node); } return element; }
Example 2
Source File: ValidationResponse.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
public ValidationResponse(final ConstraintViolationException cause) { super(false, new ArrayList<>()); //noinspection ThrowableResultOfMethodCallIgnored checkNotNull(cause); Set<ConstraintViolation<?>> violations = cause.getConstraintViolations(); if (violations != null && !violations.isEmpty()) { for (ConstraintViolation<?> violation : violations) { List<String> entries = new ArrayList<>(); // iterate path to get the full path Iterator<Node> it = violation.getPropertyPath().iterator(); while (it.hasNext()) { Node node = it.next(); if (ElementKind.PROPERTY == node.getKind() || (ElementKind.PARAMETER == node.getKind() && !it.hasNext())) { if (node.getKey() != null) { entries.add(node.getKey().toString()); } entries.add(node.getName()); } } if (entries.isEmpty()) { if (messages == null) { messages = new ArrayList<>(); } messages.add(violation.getMessage()); } else { if (errors == null) { errors = new HashMap<>(); } errors.put(Joiner.on('.').join(entries), violation.getMessage()); } } } else if (cause.getMessage() != null) { messages = new ArrayList<>(); messages.add(cause.getMessage()); } }