-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support a fixed list of Map keys statically @WithKeys
- Loading branch information
Showing
6 changed files
with
185 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
implementation/src/main/java/io/smallrye/config/WithKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.smallrye.config; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Provides a list of map keys when populating {@link java.util.Map} types. The provided list will effectively | ||
* substitute the lookup in {@link SmallRyeConfig#getPropertyNames()} for map keys. Each key must exist in the final | ||
* configuration (relative in the mapping path segment), or the mapping will fail with a | ||
* {@link java.util.NoSuchElementException}. | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.METHOD, ElementType.TYPE_USE }) | ||
public @interface WithKeys { | ||
String[] value() default {}; | ||
|
||
Class<? extends Supplier<List<String>>> provider() default EmptySupplier.class; | ||
|
||
class EmptySupplier implements Supplier<List<String>> { | ||
@Override | ||
public List<String> get() { | ||
return List.of(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.