private Object doConvertInput(ConversionService<?> conversionService, Argument<?> arg, Object object) { ArgumentConversionContext conversionContext = ConversionContext.of(arg); Optional<?> convert = conversionService.convert(object, conversionContext); if (convert.isPresent()) { return convert.get(); } else { Optional<ConversionError> lastError = conversionContext.getLastError(); if (lastError.isPresent()) { throw new ConversionErrorException(arg, lastError.get()); } } return null; } }
@Override public BindingResult<T> bind(ArgumentConversionContext<T> context, HttpRequest<?> source) { Optional<?> body = source.getBody(); if (!body.isPresent()) { //noinspection unchecked return BindingResult.EMPTY; } else { Object o = body.get(); Optional<T> converted = conversionService.convert(o, context); final Optional<ConversionError> lastError = context.getLastError(); //noinspection OptionalIsPresent if (lastError.isPresent()) { return new BindingResult<T>() { @Override public Optional<T> getValue() { return Optional.empty(); } @Override public List<ConversionError> getConversionErrors() { return Collections.singletonList(lastError.get()); } }; } else { return () -> converted; } } } }
boundArguments[i] = null; } else { final Optional<ConversionError> lastError = conversionContext.getLastError(); if (lastError.isPresent()) { throw new ConversionErrorException(argument, lastError.get());
value = (UnresolvedArgument) () -> { ArgumentBinder.BindingResult result = argumentBinder.bind(conversionContext, request); Optional<ConversionError> lastError = conversionContext.getLastError(); if (lastError.isPresent()) { return (ArgumentBinder.BindingResult) () -> lastError;
private static String buildConversionMessage(String property, ArgumentConversionContext conversionContext) { Optional<ConversionError> lastError = conversionContext.getLastError(); if (lastError.isPresent()) { ConversionError conversionError = lastError.get(); return "Error resolving property value [" + property + "]. Unable to convert value " + conversionError.getOriginalValue().map(o -> "[" + o + "]").orElse("") + " to target type [" + conversionContext.getArgument().getTypeString(true) + "] due to: " + conversionError.getCause().getMessage(); } else { return "Error resolving property value [" + property + "]. Property doesn't exist"; } } }
private static String buildConversionMessage(String property, ArgumentConversionContext conversionContext) { Optional<ConversionError> lastError = conversionContext.getLastError(); if (lastError.isPresent()) { ConversionError conversionError = lastError.get(); return "Error resolving property value [" + property + "]. Unable to convert value " + conversionError.getOriginalValue().map(o -> "[" + o + "]").orElse("") + " to target type [" + conversionContext.getArgument().getTypeString(true) + "] due to: " + conversionError.getCause().getMessage(); } else { return "Error resolving property value [" + property + "]. Property doesn't exist"; } } }
@Override public BindingResult<T> bind(ArgumentConversionContext<T> context, HttpRequest<?> source) { Optional<?> body = source.getBody(); if (!body.isPresent()) { //noinspection unchecked return BindingResult.EMPTY; } else { Object o = body.get(); Optional<T> converted = conversionService.convert(o, context); final Optional<ConversionError> lastError = context.getLastError(); //noinspection OptionalIsPresent if (lastError.isPresent()) { return new BindingResult<T>() { @Override public Optional<T> getValue() { return Optional.empty(); } @Override public List<ConversionError> getConversionErrors() { return Collections.singletonList(lastError.get()); } }; } else { return () -> converted; } } } }
ArgumentConversionContext conversionContext = ConversionContext.of(requiredArgument); Optional converted = conversionService.convert(value, conversionContext); Object result = converted.isPresent() ? converted.get() : conversionContext.getLastError().orElse(null); if (result != null) { newVariables.put(name, result);
value = (UnresolvedArgument) () -> { ArgumentBinder.BindingResult result = argumentBinder.bind(conversionContext, request); Optional<ConversionError> lastError = conversionContext.getLastError(); if (lastError.isPresent()) { return (ArgumentBinder.BindingResult) () -> lastError;