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.

35 lines
1003 B
Java

2 years ago
package com.xydl.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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", 1606800979591089792L);
}});
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;
}
}