【发布时间】:2021-03-18 16:46:42
【问题描述】:
我想使用 JAVA 将 JSON 对象的列表转换为 gzip 文件
下面是我的 JSON 文件
[
{
"id": "01",
"Status": "Open",
"siteId": "01",
"siteName": "M1"
},
{
"id": "02",
"Status": "Open",
"siteId": "02",
"siteName": "M2"
},
{
"id": "03",
"Status": "Open",
"siteId": "03",
"siteName": "M3"
}
]
写到现在的代码:
public static void main(String args[]) throws IOException
{
final ObjectMapper objectMapper = new ObjectMapper();
String fileName = "jsonList.json";
ClassLoader classLoader = className.class.getClassLoader();
File file = new File(classLoader.getResource(fileName).getFile());
System.out.println("File Found : " + file.exists());
List<document> list = objectMapper.readValue(file,new TypeReference<List<document>>(){});
System.out.println("List of json objects");
//code to compress list of json objects (list)
}
文档类
public class document {
public String id;
public String status;
public String sideId;
public String siteName;
}
请建议我压缩列表的代码 谢谢!
【问题讨论】: