-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Right now, our Converter interface is generic type for the conversion result, but the conversion original value is fixed to a String.
It might be interesting for our top level conversion to support a generic type on the original value as well, like:
public interface Converter<S, D> extends Serializable {
D convert(S value);
}The motivations behind this is to better support requirements in MP JWT. Original issue here:
microprofile/microprofile-jwt-auth#100
The source object from where values are retrieved from is a Json structure (the JWT). Values are represented as the Json counterparts (JsonObject, JsonNumber, etc), so in fact, our conversion needs to call .toString on these and perform additional operations back and forward for the final conversion to take place.
With String conversion
Object claim = jsonWebToken.getClaim(claimName);
String value = claim.toString(); // this does Integer.toString(num);
Integer integer = converters.convertValue(value, Integer.class); // and we convert from a string to int again.With Source and Target
Object claim = jsonWebToken.getClaim(claimName);
Integer integer = converters.convertValue(value, Integer.class);
JsonNumberToIntegerConverter implements Converter<JsonNumber,Integer> {
Integer convert(JsonNumber value) {
return value.intValue();
}
}Metadata
Metadata
Assignees
Labels
No labels