0
在我的休息服务中,我试图使用multipart/form-data上传带有JSON对象的文件。我在我的后端使用Resteasy MultipartFormDataInput处理请求和访问文件和JSON对象是否支持resteasy自动将String/JSON MultipartFormDataInput映射到使用jackson的对象?
我可以像下面那样处理我的文件和JSON对象;
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void uploadFile(MultipartFormDataInput input) throws IOException {
Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
List<InputPart> fileInputParts = uploadForm.get("uploadedFile");
List<InputPart> jsonInputParts = uploadForm.get("content");
//convert the uploaded file to inputstream
InputStream inputStream = fileInputParts.get(0).getBody(InputStream.class, null);
byte[] bytes = IOUtils.toByteArray(inputStream);
//Convert the uploaded JSON object
GenericRestBean bean = new ObjectMapper().readValue(jsonInputParts .get(0).getBodyAsString(), GenericRestBean.class);
我正在使用杰克逊对象映射器来将主体字符串转换为JSON对象。这里的问题是这个映射会忽略正常的bean验证,我需要手动重新实现它。
是否resteasy支持自动映射字符串/ JSON部分使用杰克逊的对象?如果是,任何人都可以帮助我从MultipartFormDataInput对象中获取此对象?