feign-form
feign-form copied to clipboard
POJO encoder doesn't handle final fields
Final fields are ignored in PojoUtils.toMap:
@SneakyThrows
public static Map<String, Object> toMap (@NonNull Object object) {
val result = new HashMap<String, Object>();
val type = object.getClass();
val setAccessibleAction = new SetAccessibleAction();
for (val field : type.getDeclaredFields()) {
val modifiers = field.getModifiers();
if (isFinal(modifiers) || isStatic(modifiers)) {
continue;
}
setAccessibleAction.setField(field);
AccessController.doPrivileged(setAccessibleAction);
val fieldValue = field.get(object);
if (fieldValue == null) {
continue;
}
val propertyKey = field.isAnnotationPresent(FormProperty.class)
? field.getAnnotation(FormProperty.class).value()
: field.getName();
result.put(propertyKey, fieldValue);
}
return result;
}
This means we can't use data classes in Kotlin. Is there a compelling reason why final fields are being ignored?
can be connected with: #95
This means we can't use data classes in Kotlin.
You can use them, but you cant use val
, just var
(valid for both class and data class)
This has broader consequences: not only final fields are silently ignored, but also it requires all form params to be actual fields. I can imagine a scenario where form param is calculated on the fly and is not backed by any field (e.g. String getFoo() { return "xxx" }
. On the other hand, it will send private fields that are not exposed from the class and therefore not a part of it's bean definition; for example Kotlin delegates, etc.
Any reason why param extraction is done this way instead of using standard java.beans.Introspector
?