/**
* 首字母小写
* author:wp
*/
public static Object keyFirstToLower(Object obj) throws Exception {
if(obj != null){
if(obj instanceof List){
List<Map<String,Object>> list = (List<Map<String, Object>>) obj;
List<Map<String,Object>> listRes = new ArrayList<Map<String,Object>>();
if(list != null && list.size() > 0){
for (Map<String, Object> map : list) {
listRes.add(toLower(map));
}
return listRes;
}
}else if(obj instanceof Map){
Map<String,Object> result = new HashMap<String,Object>();
Map<String,Object> map = (Map<String, Object>) obj;
if(map!= null && !map.isEmpty()){
result = toLower(map);
return result;
}
}
}
return null;
}
private static Map<String,Object> toLower(Map<String, Object> map) {
Map<String,Object> result = new HashMap<String,Object>();
try {
if(map != null && !map.isEmpty()){
Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry<String, Object> entry = iterator.next();
String key = entry.getKey();
Object value = entry.getValue();
String firstChar = String.valueOf(key.charAt(0));
key = key.replaceFirst(firstChar, firstChar.toLowerCase());
result.put(key, String.valueOf(entry.getValue()));
if(value instanceof List){
List<Map<String,Object>> list = (List<Map<String, Object>>) value;
List<Map<String,Object>> listRes = new ArrayList<Map<String,Object>>();
if(list != null && list.size() > 0){
for (Map<String, Object> map2 : list) {
Map<String,Object> mapres = (Map<String, Object>) keyFirstToLower(map2);
listRes.add(mapres);
}
result.put(key, listRes);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
logger.info("=========result"+result.toString());
return result;
}