Polish previous commit
Add author tag Rename 'getPayloadType' method to 'getGenericType' and ad javadoc Resolves #543
This commit is contained in:
@@ -46,6 +46,8 @@ import org.springframework.util.ReflectionUtils;
|
||||
* Set of utility operations to interrogate function definitions.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Andrey Shlykov
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public final class FunctionTypeUtils {
|
||||
@@ -63,14 +65,21 @@ public final class FunctionTypeUtils {
|
||||
* @return 'true' if this type represents a {@link Collection}. Otherwise 'false'.
|
||||
*/
|
||||
public static boolean isTypeCollection(Type type) {
|
||||
type = getPayloadType(type);
|
||||
type = getGenericType(type);
|
||||
Type rawType = type instanceof ParameterizedType ? ((ParameterizedType) type).getRawType() : type;
|
||||
|
||||
return rawType instanceof Class<?> && Collection.class.isAssignableFrom((Class<?>) rawType);
|
||||
}
|
||||
|
||||
public static Type getPayloadType(Type type) {
|
||||
if (isPublisher(type)) {
|
||||
/**
|
||||
* A convenience method identical to {@link #getImmediateGenericType(Type, int)}
|
||||
* for cases when provided 'type' is {@link Publisher} or {@link Message}.
|
||||
*
|
||||
* @param type type to interrogate
|
||||
* @return generic type if possible otherwise the same type as provided
|
||||
*/
|
||||
public static Type getGenericType(Type type) {
|
||||
if (isPublisher(type) || isMessage(type)) {
|
||||
type = getImmediateGenericType(type, 0);
|
||||
}
|
||||
if (isMessage(type)) {
|
||||
|
||||
@@ -764,7 +764,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
if (value instanceof Message<?>) { // see AWS adapter with Optional payload
|
||||
if (messageNeedsConversion(rawType, (Message<?>) value)) {
|
||||
convertedValue = FunctionTypeUtils.isTypeCollection(type)
|
||||
? messageConverter.fromMessage((Message<?>) value, (Class<?>) rawType, FunctionTypeUtils.getPayloadType(type))
|
||||
? messageConverter.fromMessage((Message<?>) value, (Class<?>) rawType, FunctionTypeUtils.getGenericType(type))
|
||||
: messageConverter.fromMessage((Message<?>) value, (Class<?>) rawType);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Converted from Message: " + convertedValue);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.function.context.config;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.springframework.cloud.function.json.JsonMapper;
|
||||
@@ -32,6 +31,8 @@ import org.springframework.util.MimeType;
|
||||
* actual conversion via {@link JsonMapper} instance.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Andrey Shlykov
|
||||
*
|
||||
* @since 3.0.4
|
||||
*/
|
||||
public class JsonMessageConverter extends AbstractMessageConverter {
|
||||
@@ -74,13 +75,9 @@ public class JsonMessageConverter extends AbstractMessageConverter {
|
||||
if (targetClass.isInstance(message.getPayload())) {
|
||||
return message.getPayload();
|
||||
}
|
||||
Object result = null;
|
||||
if (conversionHint == null) {
|
||||
result = jsonMapper.fromJson(message.getPayload(), targetClass);
|
||||
}
|
||||
else if (conversionHint instanceof ParameterizedType) {
|
||||
result = jsonMapper.fromJson(message.getPayload(), (Type) conversionHint);
|
||||
}
|
||||
|
||||
Type convertToType = conversionHint == null ? targetClass : (Type) conversionHint;
|
||||
Object result = jsonMapper.fromJson(message.getPayload(), convertToType);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user