Class ReflectiveFieldResolver

java.lang.Object
in.co.akshitbansal.springwebquery.resolver.ReflectiveFieldResolver

public class ReflectiveFieldResolver extends Object
Resolves dotted field paths against a root class using reflection.

The resolver is used for structural path traversal rather than direct value access. Given a path such as profile.address.city, it resolves each segment in order and returns the corresponding Field objects as an immutable list.

Resolution is performed segment by segment starting from the configured root class. For each segment, the resolver:

  • looks for a declared field on the current class
  • if not found, continues searching up the superclass hierarchy
  • uses the resolved field's type as the basis for the next segment

Container-like field types are unwrapped before the next segment is resolved:

  • array types resolve to their component type
  • Collection types resolve to their first generic type argument
  • all other types are used as declared

The resolver works with declared fields, including non-public ones, but it does not make them accessible. It also searches only the class/superclass hierarchy; interfaces are not inspected for fields.

No special path syntax is supported beyond dot-separated field names. Empty or unresolvable segments fail immediately.

  • Constructor Details

    • ReflectiveFieldResolver

      public ReflectiveFieldResolver()
  • Method Details

    • resolveFieldPath

      public List<Field> resolveFieldPath(@NonNull @NonNull String path)
      Resolves a dotted field path from the configured root class.

      The path is split on dots and processed left to right. Each resolved field becomes the structural context for the next segment after array and collection unwrapping has been applied. For example, when resolving accounts.portfolios.code, if accounts is a List<Account>, the next segment is resolved against Account rather than List.

      The returned list contains one Field per path segment in the same order as the input path. The final element therefore represents the terminal field in the path.

      Parameters:
      path - dotted field path to resolve
      Returns:
      immutable list of fields representing the resolved path
      Throws:
      IllegalArgumentException - if the path is empty or any segment cannot be resolved in the current structural context
      UnsupportedOperationException - if traversal reaches a collection whose element type cannot be resolved reflectively