@Override public Result<T> convertToModel(PRESENTATION value, ValueContext context) { Result<MODEL> model = Converter.this.convertToModel(value, context); return model.flatMap(v -> other.convertToModel(v, context)); }
@Override public Result<FIELDVALUE> convertToModel(FIELDVALUE value, ValueContext context) { if (delegate == null) { return Result.ok(value); } else { return delegate.convertToModel(value, context); } }
/** * Returns the field value run through all converters and validators, * but doesn't pass the {@link BindingValidationStatus} to any status * handler. * * @return the result of the conversion */ private Result<TARGET> doConversion() { FIELDVALUE fieldValue = field.getValue(); return converterValidatorChain.convertToModel(fieldValue, createValueContext()); }
/** * Parses a given string as a value of given type. * * @param value * String value to convert. * @param type * Expected result type. * @return String converted to the expected result type using a registered * converter for that type. */ public <T> T parse(String value, Class<? extends T> type) { Converter<String, T> converter = findConverterFor(type); if (converter != null) { Result<T> result = converter.convertToModel(value, new ValueContext()); return result.getOrThrow(msg -> new IllegalArgumentException(msg)); } else { return null; } }
private MODEL getModelSafely(PRESENTATION value, ValueContext context) { try { return (MODEL) delegate.convertToModel(value, context).getOrThrow(e -> new IllegalArgumentException(String.valueOf(e))); } catch (Throwable throwable) { log.info(throwable.getMessage()); return null; } } }
/** * Convert the presentation value type to model value type. * @param value Value to convert * @return Converted value */ private V convertToModel(T value) { return converter.convertToModel(value, _valueContext()).getOrThrow(error -> new RuntimeException(error)); }
protected ITEM toItem(S selection) { return requireItemConverter().convertToModel(selection, new ValueContext(this, this, findLocale())).getOrThrow( m -> new IllegalArgumentException("Failed to convert selection value [" + selection + "]: " + m)); }