Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.hibernate.validator.HibernateValidator;
import org.hibernate.validator.path.PropertyNode;

import org.junit.Assert;
import org.junit.Test;

/**
Expand Down Expand Up @@ -60,6 +61,13 @@ public void testPropertyNodeGetValueForSet() {
assertEquals( node.getName(), "name" );
assertEquals( node.as( PropertyNode.class ).getValue(), "Bob" );
//end::include[]
if ( path instanceof org.hibernate.validator.path.Path hvPath ) {
assertEquals( hvPath.getLeafNode().getName(), "name" );
assertEquals( hvPath.getLeafNode().as( PropertyNode.class ).getValue(), "Bob" );
}
else {
Assert.fail( "Unexpected path node type: " + path.getClass().getName() );
}

assertFalse( nodeIterator.hasNext() );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.hibernate.validator.internal.engine.path;

import java.io.Serial;
import java.io.Serializable;
import java.lang.invoke.MethodHandles;
import java.util.Arrays;
Expand Down Expand Up @@ -31,8 +32,8 @@
public class MaterializedNode
implements PropertyNode, MethodNode, ConstructorNode, BeanNode, ParameterNode, ReturnValueNode, CrossParameterNode, ContainerElementNode,
org.hibernate.validator.path.PropertyNode, org.hibernate.validator.path.ContainerElementNode, Serializable {
// @Serial
// private static final long serialVersionUID = 2075466571633860499L;
@Serial
private static final long serialVersionUID = -7629728442122634981L;
private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[] { };

private static final Log LOG = LoggerFactory.make( MethodHandles.lookup() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import java.io.Serializable;
import java.util.Iterator;

import jakarta.validation.Path;
import org.hibernate.validator.path.Path;


final class MaterializedPath implements Path, Serializable {

@Serial
private static final long serialVersionUID = -8906501301223202169L;
private static final long serialVersionUID = 1264131890253015968L;

private static final String PROPERTY_PATH_SEPARATOR = ".";

Expand Down Expand Up @@ -71,4 +72,9 @@ static String asString(MaterializedNode currentLeafNode) {
}
return builder.toString();
}

@Override
public Node getLeafNode() {
return leafNode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class MutableNode
implements Path.PropertyNode, Path.MethodNode, Path.ConstructorNode, Path.BeanNode, Path.ParameterNode, Path.ReturnValueNode, Path.CrossParameterNode, Path.ContainerElementNode,
org.hibernate.validator.path.PropertyNode, org.hibernate.validator.path.ContainerElementNode, Serializable {
@Serial
private static final long serialVersionUID = 2075466571633860499L;
private static final long serialVersionUID = 3259464108481054555L;
private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[] { };

private static final Log LOG = LoggerFactory.make( MethodHandles.lookup() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import java.util.regex.Pattern;

import jakarta.validation.ElementKind;
import jakarta.validation.Path;

import org.hibernate.validator.internal.metadata.aggregated.ExecutableMetaData;
import org.hibernate.validator.internal.util.Contracts;
import org.hibernate.validator.internal.util.logging.Log;
import org.hibernate.validator.internal.util.logging.LoggerFactory;
import org.hibernate.validator.path.Path;

/**
* Internal, mutable implementation of {@code jakarta.validation.Path}.
Expand All @@ -31,7 +31,7 @@
*/
public final class MutablePath implements Path, Serializable {
@Serial
private static final long serialVersionUID = 7564511574909882392L;
private static final long serialVersionUID = 2464836778339203598L;
private static final Log LOG = LoggerFactory.make( MethodHandles.lookup() );

private static final String PROPERTY_PATH_SEPARATOR = ".";
Expand Down Expand Up @@ -182,6 +182,7 @@ public void removeLeafNode() {
}
}

@Override
public MutableNode getLeafNode() {
return currentLeafNode;
}
Expand Down
21 changes: 21 additions & 0 deletions engine/src/main/java/org/hibernate/validator/path/Path.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.validator.path;

import org.hibernate.validator.Incubating;

/**
* An extended representation of the validation path, provides Hibernate Validator specific functionality.
*/
@Incubating
public interface Path extends jakarta.validation.Path {

/**
* @return The leaf node of the current path.
* This is a shortcut method to iterating over the path till the last node.
*/
jakarta.validation.Path.Node getLeafNode();

}
Loading