bean转map
/**
* bean转map
*/
public static <T> Map<String, Object> beanToMap(T bean) {
Map<String, Object> map = new HashMap<>();
if (bean != null) {
BeanMap beanMap = BeanMap.create(bean);
for (Object key : beanMap.keySet()) {
map.put(key.toString(), beanMap.get(key));
}
}
return map;
}
List<Bean> 转 List<Map<String,Object>>
public static <T> List<Map<String, Object>> listBeanToListMap(List<T> src) {
List<Map<String, Object>> mapList = null;
if (CollectionUtils.isNotEmpty(src)) {
mapList = Lists.newArrayListWithExpectedSize(src.size());
Map<String, Object> oneLineData = null;
T bean = null;
for (int i = 0, size = src.size(); i < size; i++) {
bean = src.get(i);
oneLineData = beanToMap(bean);
mapList.add(oneLineData);
}
}
return mapList;
}
字符串转JSONObject
String s ="";
JSONObject json = JSON.parseObject(s,JSONObject.class);
字符串转List<Entity>
List<Entity> list = JSON.parseArray(s,Entity.class);
Entity实体类转JSONObject
JSONObject json =(JSONObject)JSONObject .toJSON(Entity);
字符串转实体类
Entity entity = JSONObject .toJavaObject(s,Entity.class);
List转数组
List<Integer> list = Lists.newArrayList();
String[] strings = list.toArray(new String[list.size()]);
数组转集合
String[] strings = list.toArray(new String[list.size()]);
List<String> strings = Arrays.asList(strings);