Skip to content

Make our Converter Interface Converter<S,T> #5

@radcortez

Description

@radcortez

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions