Java tutorial
//package com.java2s; //License from project: Apache License import android.text.TextUtils; import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; public class Main { public static Map<String, String> beanToMap(Object object) { Map<String, String> params = new HashMap<>(); if (null == object) { return params; } try { Field[] fields = object.getClass().getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); String fieldName = field.getName(); Object fieldObj = field.get(object); if (fieldObj != null && fieldObj.getClass() == String.class) { String fieldValue = (String) fieldObj; if (!TextUtils.isEmpty(fieldValue)) { if (!TextUtils.isEmpty(fieldValue)) { fieldValue = fieldValue.replaceAll("\"", "%22"); } params.put(fieldName, fieldValue); } } } return params; } catch (Exception e) { e.printStackTrace(); } return params; } }