Search in sources :

Example 1 with Param

use of feign.Param in project feign by OpenFeign.

the class BeanQueryMapEncoder method encode.

@Override
public Map<String, Object> encode(Object object) throws EncodeException {
    try {
        ObjectParamMetadata metadata = getMetadata(object.getClass());
        Map<String, Object> propertyNameToValue = new HashMap<String, Object>();
        for (PropertyDescriptor pd : metadata.objectProperties) {
            Method method = pd.getReadMethod();
            Object value = method.invoke(object);
            if (value != null && value != object) {
                Param alias = method.getAnnotation(Param.class);
                String name = alias != null ? alias.value() : pd.getName();
                propertyNameToValue.put(name, value);
            }
        }
        return propertyNameToValue;
    } catch (IllegalAccessException | IntrospectionException | InvocationTargetException e) {
        throw new EncodeException("Failure encoding object into query map", e);
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException) EncodeException(feign.codec.EncodeException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Param(feign.Param)

Aggregations

Param (feign.Param)1 EncodeException (feign.codec.EncodeException)1 IntrospectionException (java.beans.IntrospectionException)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1