Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
charphi opened this issue Feb 22, 2024 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@charphi
Copy link
Member

charphi commented Feb 22, 2024

@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);
  }
}
@charphi charphi added the enhancement New feature or request label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant