0

我想压缩 json 对象运行时。(jackkon + Gzip)

我想压缩生成运行时使用的 json 文件

public static String compress(String str) throws IOException {
    if (str == null || str.length() == 0) {
        return str;
    }
    System.out.println("String length : " + str.length());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(out);
    gzip.write(str.getBytes());
    gzip.close();
    String outStr = out.toString("ISO-8859-1");
    System.out.println("Output String lenght : " + outStr.length());
    return outStr;
 }

如何创建 json 文件运行时并将其传递给compress方法?用于压缩,因为objectMapper.writeValue返回 void。

ObjectMapper objectMapper = new ObjectMapper();
objectMapper.writeValue("???", getTransaction());
4

0 回答 0