Class FromStringValueConverter<T>
java.lang.Object
com.soklet.converter.AbstractValueConverter<String,T>
com.soklet.converter.FromStringValueConverter<T>
- All Implemented Interfaces:
ValueConverter<String,
T>
@ThreadSafe
public abstract class FromStringValueConverter<T>
extends AbstractValueConverter<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
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class com.soklet.converter.AbstractValueConverter
convert, getFromType, getToType, performConversion, toString
-
Constructor Details
-
FromStringValueConverter
public FromStringValueConverter()Ensures that the 'from' type of this converter isString
.
-