Optional applyTypeAssignment()

in src/main/java/com/microsoft/azure/functions/worker/binding/DataOperations.java [125:150]


	Optional<R> applyTypeAssignment(T sourceValue, Type targetType) throws Exception {
		Optional<R> resultValue = null;

		if (sourceValue != null) {
			CheckedBiFunction<T, Type, R> matchingOperation = this.targetOperations
					.get(TypeUtils.getRawType(targetType, null));
			if (matchingOperation != null) {
				resultValue = Optional.ofNullable(matchingOperation).map(op -> op.tryApply(sourceValue, targetType));
			} else {
				try {
					Object jsonResult = RpcUnspecifiedDataTarget.toJsonData(sourceValue);
					resultValue = (Optional<R>) Optional.ofNullable(jsonResult);

				} catch (Exception ex) {
					WorkerLogManager.getSystemLogger().warning(ExceptionUtils.getRootCauseMessage(ex));
					Object stringResult = RpcUnspecifiedDataTarget.toJsonData(sourceValue);
					resultValue = (Optional<R>) Optional.ofNullable(stringResult);
				}
			}
		}

		if (resultValue == null || !resultValue.isPresent()) {
			resultValue = ((Optional<R>) Optional.ofNullable(generalAssignment(sourceValue, targetType)));
		}
		return resultValue;
	}