Skip to content

Add support of types representable as String to ServiceId annotation #325

@charphi

Description

@charphi

@ServiceId annotation currently supports only String as a return type.
I would be useful to support other types that can be represented as String such as URI or anything that implements CharSequence.

Current behavior:

@ServiceDefinition(quantifier = Quantifier.MULTIPLE)
public interface HashAlgorithm {

  @ServiceId(pattern = ServiceId.SCREAMING_KEBAB_CASE)
  String getName();

  String hashToHex(byte[] input);

  static void main(String[] args) {
    HashAlgorithmLoader.load()
      .stream()
      .filter(algo -> algo.getName().equals("SHA-256"))
      .findFirst()
      .map(algo -> algo.hashToHex("hello".getBytes(UTF_8)))
      .ifPresent(System.out::println);
  }
}

Expected possibility:

@ServiceDefinition(quantifier = Quantifier.MULTIPLE)
public interface HashAlgorithm {

  @ServiceId(pattern = ServiceId.SCREAMING_KEBAB_CASE, formatMethodName = "toASCIIString")
  URI getIdentifier();

  String hashToHex(byte[] input);

  static void main(String[] args) {
    HashAlgorithmLoader.load()
      .stream()
      .filter(algo -> algo.getIdentifier().toASCIIString().equals("SHA-256"))
      .findFirst()
      .map(algo -> algo.hashToHex("hello".getBytes(UTF_8)))
      .ifPresent(System.out::println);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions