Skip to content

Commit 88c3ecd

Browse files
committed
Add lookup context injection annotations
1 parent dcb961c commit 88c3ecd

File tree

10 files changed

+359
-72
lines changed

10 files changed

+359
-72
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ CHANGELOG
3030
match field names in the database: for records, component names are used;
3131
for classes, Java parameter names are used (when compiled with
3232
`-parameters`). Annotations still take precedence when present.
33+
* Added `@MaxMindDbIpAddress` and `@MaxMindDbNetwork` annotations to inject
34+
the lookup IP address and resulting network into constructors. Annotation
35+
metadata is cached per type to avoid repeated reflection overhead.
3336

3437
3.2.0 (2025-05-28)
3538
------------------

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ Defaults for missing values
160160
) { }
161161
```
162162

163+
Lookup context injection
164+
165+
- Use `@MaxMindDbIpAddress` to inject the IP address being decoded.
166+
Supported parameter types are `InetAddress` and `String`.
167+
- Use `@MaxMindDbNetwork` to inject the network of the resulting record.
168+
Supported parameter types are `Network` and `String`.
169+
- Context annotations cannot be combined with `@MaxMindDbParameter` on the same
170+
constructor argument. Values are populated for every lookup without being
171+
cached between different IPs.
172+
163173
You can also use the reader object to iterate over the database.
164174
The `reader.networks()` and `reader.networksWithin()` methods can
165175
be used for this purpose.

src/main/java/com/maxmind/db/CachedConstructor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ record CachedConstructor<T>(
88
Class<?>[] parameterTypes,
99
java.lang.reflect.Type[] parameterGenericTypes,
1010
Map<String, Integer> parameterIndexes,
11-
Object[] parameterDefaults
11+
Object[] parameterDefaults,
12+
ParameterInjection[] parameterInjections,
13+
boolean requiresLookupContext
1214
) {}

0 commit comments

Comments
 (0)