feign-form icon indicating copy to clipboard operation
feign-form copied to clipboard

Pojo encoder not considered the super class attributes.

Open mariasekar opened this issue 4 years ago • 6 comments

Hello Feign team, The pojo encoder is not considering the base class fields. We could restrict it till Object.

While looking into feign form code, we have come across the PojoUtil.java. There is a method called "toMap() which will convert pojo to respective map objects. The reflection uses the "getDeclaredFields()" which will give only current class attributes only. Hence the base class attributes will be missed out during the map conversion. So please consider the base class attributes as well in the encoder.

Thanks for your Time, Maria Sekar

mariasekar avatar Jul 31 '19 09:07 mariasekar

Here is the code,

public static Map<String, Object> toMap (Object object) { HashMap<String, Object> result = new HashMap<String, Object>(); try { Class<?> clazz = object.getClass(); while(clazz != null) { // Dont want to proces Object.class for (Field field : clazz.getDeclaredFields()) { int modifiers = field.getModifiers(); if (isFinal(modifiers) || isStatic(modifiers)) { continue; } setFeieldAccessible(field);

                Object fieldValue = field.get(object);
                if (fieldValue == null) {
                    continue;
                }

                String propertyKey = field.isAnnotationPresent(FormProperty.class)
                        ? field.getAnnotation(FormProperty.class).value()
                        : field.getName();

                result.put(propertyKey, fieldValue);
            }
            clazz = clazz.getSuperclass();
        }

    } catch (Exception e) {

    }

    return result;
}

For the time being i have extended the formencoder and did the modifications.

mariasekar avatar Jul 31 '19 11:07 mariasekar

+1

rsercano avatar Nov 15 '19 08:11 rsercano

can be connected with: #95

slawekjaranowski avatar Oct 09 '20 06:10 slawekjaranowski

+1

Sidabw avatar May 08 '21 03:05 Sidabw