GH-562 Add type conversion documentation

Add test in AWS to showcase type conversion
Fix AWS FunctionInvoker to delegate to effectively delegate type conversion to the native mechanism of spring-cloud-function

Resolves #562
This commit is contained in:
Oleg Zhurakousky
2020-07-29 20:17:03 +02:00
parent 48b8f4ce89
commit 6b9ce4cb0c
5 changed files with 236 additions and 81 deletions

View File

@@ -77,8 +77,13 @@ public class JsonMessageConverter extends AbstractMessageConverter {
}
Type convertToType = conversionHint == null ? targetClass : (Type) conversionHint;
Object result = jsonMapper.fromJson(message.getPayload(), convertToType);
return result;
try {
return this.jsonMapper.fromJson(message.getPayload(), convertToType);
}
catch (Exception e) {
// ignore
}
return null;
}
@Override

View File

@@ -23,8 +23,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author Dave Syer
@@ -32,8 +30,6 @@ import org.apache.commons.logging.LogFactory;
*/
public class JacksonMapper extends JsonMapper {
private static Log logger = LogFactory.getLog(JsonMapper.class);
private final ObjectMapper mapper;
public JacksonMapper(ObjectMapper mapper) {
@@ -62,7 +58,7 @@ public class JacksonMapper extends JsonMapper {
}
}
catch (Exception e) {
logger.warn("Failed to convert. Possible bug as the conversion probably shouldn't have been attampted here", e);
throw new IllegalStateException("Failed to convert. Possible bug as the conversion probably shouldn't have been attampted here", e);
}
return convertedValue;
}