List<FormDataBodyPart> formDataBodyParts = formDataMultiPart.getFields(parameter.getSourceName());
FormDataBodyPart formDataBodyPart = (formDataBodyParts != null) ? formDataBodyParts.get(0) : null;
MediaType mediaType = (formDataBodyPart != null) ? formDataBodyPart.getMediaType() : MediaType.TEXT_PLAIN_TYPE;
MessageBodyWorkers messageBodyWorkers = context.getRequestContext().getWorkers();
MessageBodyReader reader = messageBodyWorkers.getMessageBodyReader(
parameter.getRawType(),
parameter.getType(),
parameter.getAnnotations(),
mediaType);
if (reader != null && !isPrimitiveType(parameter.getRawType())) {
InputStream in;
if (formDataBodyPart == null) {
if (parameter.getDefaultValue() != null) {
// Convert default value to bytes.
in = new ByteArrayInputStream(parameter.getDefaultValue().getBytes());
} else {
return null;
}
} else {
in = ((BodyPartEntity) formDataBodyPart.getEntity()).getInputStream();
}
try {
//noinspection unchecked
return reader.readFrom(
parameter.getRawType(),
parameter.getType(),
parameter.getAnnotations(),
mediaType,
context.getRequestContext().getHeaders(),
in);
} catch (IOException e) {
throw new FormDataParamException(e, extractor.getName(), extractor.getDefaultValueString());
}
} else if (extractor != null) {
MultivaluedMap<String, String> map = new MultivaluedStringMap();
try {
if (formDataBodyPart != null) {
for (FormDataBodyPart p : formDataBodyParts) {
mediaType = p.getMediaType();
reader = messageBodyWorkers.getMessageBodyReader(
String.class,
String.class,
parameter.getAnnotations(),
mediaType);