All Downloads are FREE. Search and download functionalities are using the official Maven repository.

devutility.internal.lang.ObjectUtils Maven / Gradle / Ivy

There is a newer version: 1.3.8.1
Show newest version
package devutility.internal.lang;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import devutility.internal.lang.models.EntityField;

/**
 * 
 * ObjectUtils
 * 
 * @author: Aldwin Su
 * @version: 2019-12-20 17:50:11
 */
public class ObjectUtils {
	/**
	 * Convert to http request parameter string. Such as {@literal asd=xxx&qwe=xxx}
	 * @param object Object need to convert.
	 * @return String Http request parameters.
	 * @throws InvocationTargetException from invoke method.
	 * @throws IllegalArgumentException from invoke method.
	 * @throws IllegalAccessException from invoke method.
	 */
	public static String toHttpRequestParams(Object object) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		StringBuffer buffer = new StringBuffer();
		List entityFields = ClassUtils.getEntityFields(object.getClass());

		for (EntityField entityField : entityFields) {
			Object value = entityField.getGetter().invoke(object);

			if (value != null) {
				buffer.append(String.format("%s=%s&", entityField.getField().getName(), value.toString()));
			}
		}

		if (buffer.length() > 0) {

		}

		return buffer.toString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy