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.
|
|
|
package com.xydl.util;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
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);
|
|
|
|
put("Timestamp", new Date().getTime());
|
|
|
|
}});
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
System.out.println(new Date().getTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|