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

org.jboss.resteasy.reactive.client.impl.ReflectionUtil Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package org.jboss.resteasy.reactive.client.impl;

import java.lang.reflect.Field;

@SuppressWarnings("unused")
public class ReflectionUtil {

    private ReflectionUtil() {
    }

    /**
     * Used by io.quarkus.resteasy.reactive.client.deployment.beanparam.FieldExtractor
     *
     * @param object object to read the field from
     * @param clazz class that declares the field
     * @param fieldName name of the field
     * @return value of the field
     */
    public static Object readField(Object object, Class clazz, String fieldName) {
        try {
            Field field = clazz.getDeclaredField(fieldName);
            if (!field.isAccessible()) {
                field.setAccessible(true);
            }
            return field.get(object);
        } catch (IllegalAccessException | NoSuchFieldException e) {
            throw new IllegalArgumentException("Cannot read '" + fieldName + "' field from " + object + " of class " + clazz);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy