public static Map<String,String> beanToMap(Object bean) {
Map<String,String> params =Maps.newHashMap();
try {
PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
PropertyDescriptor[] descriptors = propertyUtilsBean.getPropertyDescriptors(bean);
for (int i = 0; i < descriptors.length; i++) {
String name = descriptors[i].getName();
if (!"class".equals(name)) {
Object value = propertyUtilsBean.getNestedProperty(bean, name);

if(value!=null && value.toString()!=null){
if(isJavaClass(value.getClass()) && !(value instanceof Collection<?>) ){
params.put(name,value.toString());
}else{

if(value==null||name.startsWith("global")){
continue;
}
String jsonObject=JsonMapper.getInstance().toJsonString(value);
if(null==jsonObject){
params.put(name,value.toString());
}else{
params.put(name,jsonObject.toString());
}
}
}

}
}
} catch (Exception e) {
e.printStackTrace();
}
return params;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2021-09-16
  • 2021-12-08
  • 2021-08-17
  • 2022-12-23
相关资源
相似解决方案