You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB
Java

2 years ago
package com.xydl.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
2 years ago
import java.util.*;
2 years ago
public class FormatUtil {
public static String list2Json(List list){
ObjectMapper objectMapper = new ObjectMapper();
List<Map<String,Object>> assetList = new ArrayList<>();
assetList.add(new HashMap<String,Object>(){{
put("AssetCode","ironCore");
put("AttributeList",list);
2 years ago
put("Timestamp", new Date().getTime());
2 years ago
}});
Map<String,Object> resultMap = new HashMap<String,Object>(){{
put("AssetList",assetList);
}};
String jsonString = null;
try {
jsonString = objectMapper.writeValueAsString(resultMap);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return jsonString;
}
2 years ago
public static void main(String[] args) {
System.out.println(new Date().getTime());
}
2 years ago
}