use of org.mule.runtime.api.metadata.DataType.fromType in project mule by mulesoft.
the class ReflectiveExpressionFunctionExecutor method getWrapper.
private Function<Object, Object> getWrapper(Parameter parameter) {
Type[] generics = parameter.getType().getGenericInterfaces();
Class<?> type;
if (generics.length == 0) {
type = Object.class;
} else {
type = model.getAllParameterModels().stream().filter(p -> p.getModelProperty(ImplementingParameterModelProperty.class).map(mp -> mp.getParameter().getName().equals(parameter.getName())).orElse(false)).map(p -> getType(p.getType()).orElse(Object.class)).findFirst().orElseThrow(() -> new IllegalStateException(format("Missing parameter with name [%s]", parameter.getName())));
}
DataType expected = DataType.fromType(type);
return value -> {
if (value == null) {
return null;
}
if (value instanceof TypedValue) {
if (((TypedValue) value).getDataType().equals(DataType.TYPED_VALUE)) {
// DW will wrap anything of type TypedValue in a new TypedValue with DataType.TYPED_VALUE
value = ((TypedValue) value).getValue();
}
TypedValue typedValue = (TypedValue) value;
// We have to check for transformations of the value because weave won't be able to validate types
return type.isInstance(typedValue.getValue()) ? value : new TypedValue<>(transformationService.transform(typedValue.getValue(), typedValue.getDataType(), expected), typedValue.getDataType());
} else {
return new TypedValue<>(value, fromObject(value));
}
};
}
Aggregations