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 AbstractValueConverter
convert, getFromType, getToType, performConversion, toStringModifier and TypeMethodDescriptionConvertsfromto an instance ofT.The 'converting from' type.The 'converting to' type.performConversion(String from) Subclasses must implement this method to convert a 'from' instance to a 'to' instance.toString()
-
Constructor Details
-
FromStringValueConverter
public FromStringValueConverter()Ensures that the 'from' type of this converter isString.
-