Skip to content

Commit

Permalink
Added value alias for @BeanProperty
Browse files Browse the repository at this point in the history
@BeanProperty could only be used with a `name` property. Adding a
`value` alias allows this annotation to be used without any prefix and
just the name of the property.

Also corrected all warnings about javadoc (missing returns).

Fixes #122
  • Loading branch information
arjanvlek committed Dec 20, 2018
1 parent 5c58168 commit 6c2e500
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/main/java/io/beanmapper/BeanMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ public final Configuration getConfiguration() {

/**
* @deprecated use wrap() instead
* @return BeanMapperBuilder
*/
public BeanMapperBuilder config() {
return wrap();
}

/**
* @deprecated use wrap() instead
* @return BeanMapperBuilder
*/
public BeanMapperBuilder wrapConfig() {
return wrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* functionality in combination with Lazy to make sure BeanMapper operates within the
* transaction scope. If you do, the flush action can be rolled back, resulting in the
* original state being preserved.
* @return Whether to flush the collection after clearing or not.
*/
boolean flushAfterClear() default true;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/beanmapper/annotations/BeanProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface BeanProperty {

String name();
String name() default "";

String value() default "";

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

/**
* The role the Principal must have to be allowed access to the field or method
* @return Role required to access the field or method
*/
String[] value();

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/io/beanmapper/core/BeanMatchStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private BeanPropertyWrapper dealWithBeanProperty(
BeanPropertyWrapper wrapper = new BeanPropertyWrapper(accessor.getName());
if (accessor.findAnnotation(io.beanmapper.annotations.BeanProperty.class) != null) {
wrapper.setMustMatch();
wrapper.setName(accessor.findAnnotation(io.beanmapper.annotations.BeanProperty.class).name());
wrapper.setName(getBeanPropertyName(accessor.findAnnotation(io.beanmapper.annotations.BeanProperty.class)));
// Get the other field from the location that is specified in the beanProperty annotation.
// If the field is referred to by a path, store the custom field in the other map
try {
Expand All @@ -274,4 +274,14 @@ private BeanPropertyWrapper dealWithBeanProperty(
return wrapper;
}

private String getBeanPropertyName(io.beanmapper.annotations.BeanProperty annotation) {
String beanPropertyName = annotation.value();

if (beanPropertyName.isEmpty()) {
beanPropertyName = annotation.name();
}

return beanPropertyName;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public AbstractCollectionHandler() {

/**
* Creates a new instance of the collection class
* @return
* @return new instance of the collection class
*/
abstract protected C create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class SourceWithOtherName {

@BeanProperty(name = "bothOtherName")
@BeanProperty("bothOtherName")
private String bothOtherName1;
@BeanProperty(name = "sourceOtherName")
private String sourceOtherName1;
Expand Down

0 comments on commit 6c2e500

Please sign in to comment.