open-policy-agent / open-policy-agent/java-opa-sdk

Simplify the AnnotationIntrospector SPI: return a ClassInfo instead of many per-element queries

Open
#178 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
16
Forks
24
Avg merge
8h 17m
Merged PRs (30d)
15

Description

Follow-up from PR #110 review: https://github.com/open-policy-agent/java-opa-sdk/pull/110#discussion_r3644681150 (johanfylling).

Context

AnnotationIntrospector (in opa-evaluator, io.github.open_policy_agent.opa.mapper) is the SPI the mapper consults to resolve annotation-driven property metadata without binding the evaluator to a specific JSON library. Today it exposes many fine-grained "ask a question" methods:

String findPropertyName(Method getter, Field backingField);
boolean isIgnored(Method getter, Field backingField);
boolean isNonNullInclude(Method getter, Field backingField);
String findCreatorParamName(Parameter param);
boolean isJsonCreator(Constructor<?> ctor);
boolean isJsonCreator(Method method);
Visibility findFieldVisibility(Class<?> clazz);
boolean isJsonValue(Method method);
Proposal

As suggested in review, consider inverting the shape: instead of the mapper asking the introspector a series of questions per element, give the introspector a Class<?> and have it hand back a resolved descriptor (e.g. ClassInfo) that carries the property names, ignored set, null-inclusion, creator info, visibility, and JSON-value method in one pass.

Potential benefits:

  • Simpler SPI surface (one entry point instead of eight).
  • Implementations can resolve a class once rather than being re-queried per getter/field/parameter.
  • Clearer contract for the null-argument combinations that the current per-element methods have to document.
Scope / notes
  • Not blocking; raised on PR #110 as out of scope for that change.
  • Affects opa-evaluator (the SPI + DefaultAnnotationIntrospector) and the opa-jackson implementation, plus the mapper call sites.
  • Worth confirming the one-pass model still supports lazy/partial resolution where the mapper only needs a subset.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading AnnotationIntrospector and DefaultAnnotationIntrospector in opa-evaluator, then inspect the opa-jackson implementation and mapper call sites. Confirm whether a ClassInfo-style descriptor can carry the listed metadata while preserving lazy or partial resolution. Done means the SPI and affected implementations and call sites use the agreed one-entry-point contract, with tests covering the supported metadata and null-argument behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.