Java Library

ReflectionPath

Navigate Java objects as if its a JSON tree. No more reflection boilerplate or confusing type gymnastics.

Current version: v1.0.0

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

BasicExample.java

// 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);
StrategyExample.java

// 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);
ArrayExample.java

// Access array fields
ReflectionPath arrayPath = new ReflectionPath("[String[]]");
String[] inventory = arrayPath.getAs(player, String[].class);

How It Works

ReflectionPathPath TypeName-based PathType-based PathPath ResolutionResult Cacheperson.address.city[Player].[Location]FIRST_MATCHLAST_MATCHEXACT_MATCH

Key Features

DP
Dual Path Styles

Choose between name-based dot notation or type-based bracket notation for maximum flexibility.

TS
Type Safety

Get values with type safety using generic getAs() methods that return properly typed objects.

HP
High Performance

Thread-safe implementation with path caching for optimal performance in production environments.

AR
Array 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>
For more details, check our documentation

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.

D
M
Duco & Mats