如何使用java对象而不是字符串来处理服务器端“application/json”和“application/vnd.3gpp.5gnas”的多部分请求

问题描述 投票:0回答:0

客户端到服务器在 RequestBody 中使用字符串效果很好。

@RequestMapping(method = RequestMethod.POST,value = "/createSessions",
            produces = { "application/json", "multipart/related", "application/problem+json" },
            consumes = { "application/json", "multipart/related","multipart/mixed"})
    public ResponseEntity<SessionData> testSessions(Request jettyRequest, Map<String, List<String>> httpHeaderMap, @RequestBody String sessionCreateDataMultiPart) {
        Response response = null;
        try {
            MimeMultipart mimeMultipart = new MimeMultipart(new ByteArrayDataSource(multipartData, "multipart/related"));
            for (int i = 0; i < mimeMultipart.getCount(); i++) {
                BodyPart bodyPart = mimeMultipart.getBodyPart(i);
                log.info("MultiPart: ", bodyPart);
                log.info("MultiParts: ", bodyPart);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

客户端到服务器在RequestPart中使用Java对象无法解析。


@RequestMapping(method = RequestMethod.POST,value = "/createSessions",
            produces = { "application/json", "multipart/related", "application/problem+json" },
            consumes = { "application/json", "multipart/related","multipart/mixed"})
    public ResponseEntity<SessionData> testSessions(Request jettyRequest, Map<String, List<String>> httpHeaderMap, @RequestPart SessionCreateDataMultiPart sessionCreateDataMultiPart) {
        Response response = null;
        try {
            MimeMultipart mimeMultipart = new MimeMultipart(new ByteArrayDataSource(multipartData, "multipart/related"));
            for (int i = 0; i < mimeMultipart.getCount(); i++) {
                BodyPart bodyPart = mimeMultipart.getBodyPart(i);
                log.info("MultiPart: ", bodyPart);
                log.info("MultiParts: ", bodyPart);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
spring-boot multipart
© www.soinside.com 2019 - 2024. All rights reserved.