Class ReflectionUtil
java.lang.Object
in.co.akshitbansal.springwebquery.util.ReflectionUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FieldresolveField(Class<?> type, String name) Resolves aFieldfor the given dot-separated field path, starting from the supplied root type and traversing the type hierarchy and container types as needed.
-
Constructor Details
-
ReflectionUtil
public ReflectionUtil()
-
-
Method Details
-
resolveField
Resolves aFieldfor the given dot-separated field path, starting from the supplied root type and traversing the type hierarchy and container types as needed.The resolution rules are:
- Each path segment is resolved using
getDeclaredFieldwhile walking up the superclass hierarchy. - If a resolved field is an array, traversal continues with its component type.
- If a resolved field is a
Collection, traversal continues with the collection's generic element type. - Only the last field in the path is returned.
Examples:
resolveField(User.class, "name.first"); resolveField(Order.class, "items.product.id"); resolveField(Foo.class, "values"); // List<List<String>> resolves to ListThis method performs structural type resolution only. It does not access or inspect runtime values.
- Parameters:
type- the root class from which resolution startsname- a dot-separated field path (e.g."a.b.c")- Returns:
- the
Fieldcorresponding to the last segment in the path - Throws:
QueryException- if any segment of the path cannot be resolvedUnsupportedOperationException- if an intermediate collection type does not expose resolvable generic information
- Each path segment is resolved using
-