如何使用Jackson Object Mapper将PDF读入字节数组

问题描述

我正在尝试从第三方API获取PDF,然后将其作为附件从我的API /服务器返回。我通常使用字节数组返回PDF文档,没有问题,但是,我似乎无法弄清楚如何在不从Jackson收到JSON Parse错误的情况下,将第三方api的响应转换为字节数组。

这是我试图用来从第3方API将PDF作为字节数组获取的代码:

    URI uri = URI.create(String.format(URL_INVOICE_PDF_TEMPLATE,getBaseUrl(),invoiceId));
    
    byte[] pdfBytes = null;

    try (CloseableHttpResponse res = get(uri)) 
    {
      pdfBytes = getMapper().readValue(res.getEntity().getContent(),byte[].class);
    } 
    catch (Exception e) 
    {
      if (e.getError().getHttpStatusCode() != 404)
        throw e;
    }

但是,我不断收到JsonParseException。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...