You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the introduction of record-classes, accessors without the JavaBeans-conventional prefixes (is, get, set, etc.) have become mainstream.
Furthermore, methods with the new format are already supported by popular libraries and frameworks, notably, Lombok, the Spring Framework. Some libraries comparable to BeanMapper also support the new format of accessor, or are working on support.
While support for these new types of accessors seems like a rather fundamental change, the actual work involved should be fairly trivial. I would, however, recommend making the recognition of such accessors optional, and disable it by default. This is certainly a useful feature, however, the unrestricted addition of this feature would lead to breaking changes if anyone uses a combination of the JavaBeans accessors, and the new record-style accessors.
Concretely I propose the following:
Add support for getters and setters as used in the following snippet:
Add an annotation @BeanPropertyAccessor, to support setters that take an argument that is not of the type of the field, and allow for the use of accessors that do not share the name of the field. This annotation does not enable the use of record-style accessors. To do so, an option, along the lines of boolean enableRecordStyleAccessors, would need to be set to true in the (Core)Configuration. Note that this annotation shares some intended functionality with the @BeanProperty-annotation. I propose to deprecate the use of @BeanProperty on methods, however, this should be carefully reviewed:
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface BeanPropertyAccessor {
Stringvalue();
}
With the introduction of record-classes, accessors without the JavaBeans-conventional prefixes (is, get, set, etc.) have become mainstream.
Furthermore, methods with the new format are already supported by popular libraries and frameworks, notably, Lombok, the Spring Framework. Some libraries comparable to BeanMapper also support the new format of accessor, or are working on support.
While support for these new types of accessors seems like a rather fundamental change, the actual work involved should be fairly trivial. I would, however, recommend making the recognition of such accessors optional, and disable it by default. This is certainly a useful feature, however, the unrestricted addition of this feature would lead to breaking changes if anyone uses a combination of the JavaBeans accessors, and the new record-style accessors.
Concretely I propose the following:
Add support for getters and setters as used in the following snippet:
Add support for "fluent" setters, of which the return-type is equal to the type of the declaring class:
Add an annotation
@BeanPropertyAccessor
, to support setters that take an argument that is not of the type of the field, and allow for the use of accessors that do not share the name of the field. This annotation does not enable the use of record-style accessors. To do so, an option, along the lines ofboolean enableRecordStyleAccessors
, would need to be set to true in the (Core)Configuration. Note that this annotation shares some intended functionality with the@BeanProperty
-annotation. I propose to deprecate the use of@BeanProperty
on methods, however, this should be carefully reviewed:Which would be used as follows:
The text was updated successfully, but these errors were encountered: