ReflectionPath
Navigate Java objects as if its a JSON tree. No more reflection boilerplate or confusing type gymnastics.
What is ReflectionPath?
ReflectionPath is a Java utility that makes reflection feel natural. It lets you navigate object hierarchies using intuitive path expressions, just like you'd access a JSON tree.
Navigate by name using dot notation (person.address.city
) or by type using bracket notation ([Player].[Location]
). You can even access arrays and invoke methods, all with type safety built in.
Two Path Styles for Flexibility
// Name-based field access
ReflectionPath path = new ReflectionPath("person.address.city");
String city = path.getAs(person, String.class);
// Type-based access
ReflectionPath typePath = new ReflectionPath("[Player].[ConnectionType]");
ConnectionType type = typePath.getAs(player, ConnectionType.class);
// Method invocation
ReflectionPath methodPath = new ReflectionPath("getName");
String name = methodPath.getAs(player, String.class);
// First match (default)
ReflectionPath path1 = new ReflectionPath("[String]", PathResolutionStrategy.FIRST_MATCH);
// Last match
ReflectionPath path2 = new ReflectionPath("[String]", PathResolutionStrategy.LAST_MATCH);
// Exact match (throws exception if multiple matches found)
ReflectionPath path3 = new ReflectionPath("[String]", PathResolutionStrategy.EXACT_MATCH);
// Access array fields
ReflectionPath arrayPath = new ReflectionPath("[String[]]");
String[] inventory = arrayPath.getAs(player, String[].class);
How It Works
Key Features
DPDual Path Styles
Choose between name-based dot notation or type-based bracket notation for maximum flexibility.
TSType Safety
Get values with type safety using generic getAs() methods that return properly typed objects.
HPHigh Performance
Thread-safe implementation with path caching for optimal performance in production environments.
ARArray Support
Full support for array types with simple syntax: [String[]] for accessing array fields.
Get Started
Add ReflectionPath to your Maven project:
<dependency>
<groupId>dev.pixelib</groupId>
<artifactId>reflection-path</artifactId>
<version>1.0.0</version>
</dependency>
Why We Built It
We built ReflectionPath because Java reflection is powerful but needlessly complex. Navigating object hierarchies should be as simple as accessing a JSON tree, not require dozens of lines of boilerplate code.
ReflectionPath gives you the flexibility to access objects by name or type, with clean syntax and comprehensive error handling, all while maintaining performance through smart caching.