GH-228 Added support for treating text/* CT as a special case

Resolves #228
This commit is contained in:
Oleg Zhurakousky
2018-11-16 12:46:58 +01:00
parent e9b289d995
commit c46f25a000
5 changed files with 69 additions and 35 deletions

View File

@@ -123,38 +123,34 @@ public class RequestProcessor {
.flatMap(body -> response(wrapper, body, false));
}
public Mono<ResponseEntity<?>> post(FunctionWrapper wrapper, String body,
boolean stream) {
public Mono<ResponseEntity<?>> post(FunctionWrapper wrapper, String body, boolean stream) {
Object function = wrapper.handler();
Class<?> inputType = inspector.getInputType(function);
Type itemType = getItemType(function);
Object input = body;
if (StringUtils.hasText(body) && this.mapper != null) {
if (body.startsWith("[")) {
Class<?> collectionType = Collection.class.isAssignableFrom(inputType)
? inputType
: Collection.class;
if (StringUtils.hasText(body)) {
MediaType contentType = wrapper.headers.getContentType();
if (contentType != null && "text".equalsIgnoreCase(contentType.getType())) {
input = converter.convert(function, body);
}
else if (body.startsWith("[")) {
Class<?> collectionType = Collection.class.isAssignableFrom(inputType) ? inputType : Collection.class;
input = mapper.toObject(body,
ResolvableType
.forClassWithGenerics(collectionType, (Class<?>) itemType)
.getType());
ResolvableType.forClassWithGenerics(collectionType, (Class<?>) itemType).getType());
}
else if (body.startsWith("{")) {
input = mapper.toObject(body, inputType);
}
else if (body.startsWith("\"")) {
input = body.substring(1, body.length() - 2);
}
else {
if (inputType == String.class) {
input = body;
}
else if (body.startsWith("{")) {
input = mapper.toObject(body, inputType);
}
else if (body.startsWith("\"")) {
input = body.substring(1, body.length() - 2);
}
else {
input = converter.convert(function, body);
}
input = converter.convert(function, body);
}
}
return response(wrapper, input, stream);
}