devutility.internal.lang.ObjectUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of devutility.internal Show documentation
Show all versions of devutility.internal Show documentation
Utilities for Java development
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