Add special handling for JSON Strings

Added support to JsonMessageConverter to pass string as is if input type is String
Added guard condition to RSocketListenerFunction to avoid NPE if target function can not be discovered
This commit is contained in:
Oleg Zhurakousky
2020-08-31 16:35:18 +02:00
parent 4215c92936
commit f450e4a2eb
2 changed files with 11 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.function.context.config;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import org.springframework.cloud.function.json.JsonMapper;
import org.springframework.lang.Nullable;
@@ -76,12 +77,16 @@ public class JsonMessageConverter extends AbstractMessageConverter {
return message.getPayload();
}
Type convertToType = conversionHint == null ? targetClass : (Type) conversionHint;
try {
return this.jsonMapper.fromJson(message.getPayload(), convertToType);
}
catch (Exception e) {
// ignore
if (message.getPayload() instanceof byte[] && targetClass.isAssignableFrom(String.class)) {
return new String((byte[]) message.getPayload(), StandardCharsets.UTF_8);
}
}
return null;
}