ServiceDefinition.
The annotated method must follow the following rules:
- Id method only applies to methods of a service
- Id method does not apply to static methods
- Id method must have no-args
- Id method must return
String, a built-in representable type, or any type with a format method specified viaformatMethodName - Id method must be unique
- Id method must not throw checked exceptions
- Id pattern must be valid
- Format method (if specified) must exist on the return type, be no-arg and return
String
The following JDK types are recognized as built-in representable types and do not require
an explicit formatMethodName:
- All
Enumsubtypes — usesname() java.util.UUID— usestoString()java.net.URI— usestoString()java.nio.charset.Charset— usesname()java.util.Locale— usestoLanguageTag()
Additionally, if the return type is annotated with @nbbrd.design.RepresentableAsString,
its formatMethodName attribute is used automatically (without requiring that annotation
on the processor classpath).
Resolution priority (first match wins):
- Explicit
@ServiceId(formatMethodName=...)value @RepresentableAsString(formatMethodName=...)on the return type- Built-in JDK registry listed above
- Direct
Stringreturn type
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionSpecifies the regex pattern that the ID is expected to match.
If specified, this pattern will be added to the loader as a static final field. -
Field Summary
Fields
-
Field Details
-
FLAT_CASE
- See Also:
-
UPPER_FLAT_CASE
- See Also:
-
CAMEL_CASE
- See Also:
-
PASCAL_CASE
- See Also:
-
SNAKE_CASE
- See Also:
-
SCREAMING_SNAKE_CASE
- See Also:
-
CAMEL_SNAKE_CASE
- See Also:
-
KEBAB_CASE
- See Also:
-
SCREAMING_KEBAB_CASE
- See Also:
-
TRAIN_CASE
- See Also:
-
-
Element Details
-
pattern
String patternSpecifies the regex pattern that the ID is expected to match.
If specified, this pattern will be added to the loader as a static final field.- Returns:
- a regex pattern if required, empty otherwise
- Default:
""
-
formatMethodName
String formatMethodNameSpecifies the name of a no-arg method on the return type of the annotated method that converts it to a uniqueStringrepresentation.
When specified, the annotated method may return any type (not justString), as long as that type exposes the named method returningString.This attribute is optional for types listed as built-in representable types (see class-level documentation). It is only required for types not in that list.
Example:
@ServiceId(formatMethodName = "name")onMyEnum getCategory()will useprovider.getCategory().name()as the identifier. However, anyEnumsubtype already usesname()automatically, so the explicitformatMethodNameis not needed in that case.- Returns:
- the name of the format method, or empty to use the default for built-in types
or require a direct
Stringreturn type
- Default:
""
-