Class FromStringValueConverter<T>

java.lang.Object
com.soklet.converter.AbstractValueConverter<String,T>
com.soklet.converter.FromStringValueConverter<T>
All Implemented Interfaces:
ValueConverter<String,T>

Convenience superclass which provides default implementations of ValueConverter methods that convert from String to other types.

For example:

 public record Jwt(
   String header,
   String payload,
   String signature
 ) {}

 ValueConverter<String, Jwt> jwtVc = new FromStringValueConverter<>() {
   @Nonnull
   public Optional<Jwt> performConversion(@Nullable String from) throws Exception {
     if(from == null)
       return Optional.empty();

     // JWT is of the form "a.b.c", break it into pieces
     String[] components = from.split("\\.");
     Jwt jwt = new Jwt(components[0], components[1], components[2]);
     return Optional.of(jwt);
   }
 };
See detailed documentation at https://www.soklet.com/docs/value-conversions#custom-conversions.
Author:
Mark Allen