Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_RELEASE_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

* Prevent mapper generation from a type with a generic super bound to a type with a generic extends bound (#3994)
* Fix location for Javadoc when generating the distribution zip
* Fix property name resolution for fluent setters whose second character is upper case (#4000)

### Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,14 @@ public String getPropertyName(ExecutableElement getterOrSetterMethod) {
return IntrospectorUtils.decapitalize( methodName.substring( 3 ) );
}
else {
return methodName;
// [#4000] Apply the same JavaBean-style decapitalization as for `getXyz` /
// `setXyz` accessors so that a fluent setter `xNameField(...)` resolves to
// the same property name as a JavaBean accessor `getXNameField()` /
// `setXNameField(...)`. Without this, the two are recognised as different
// properties when the second character is upper case (see Introspector spec).
return IntrospectorUtils.decapitalize(
Character.toUpperCase( methodName.charAt( 0 ) ) + methodName.substring( 1 )
);
}
}
return IntrospectorUtils.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._4000;

import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

@Mapper
public interface Issue4000Mapper {

Issue4000Mapper INSTANCE = Mappers.getMapper( Issue4000Mapper.class );

Target map(Source source);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._4000;

import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;

import static org.assertj.core.api.Assertions.assertThat;

@WithClasses({
Issue4000Mapper.class,
Source.class,
Target.class,
})
@IssueKey("4000")
public class Issue4000Test {

@ProcessorTest
public void fluentSetterWithSecondCharUpperCaseShouldMatchJavaBeanAccessor() {
Target target = Issue4000Mapper.INSTANCE.map( new Source( "value" ) );

assertThat( target.getXNameField() ).isEqualTo( "value" );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._4000;

public class Source {

private final String xNameField;

public Source(String xNameField) {
this.xNameField = xNameField;
}

public String getXNameField() {
return xNameField;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._4000;

public class Target {

private final String xNameField;

public Target(Builder builder) {
this.xNameField = builder.xNameField;
}

public String getXNameField() {
return xNameField;
}

public static Target.Builder builder() {
return new Builder();
}

public static class Builder {

private String xNameField;

public Builder xNameField(String xNameField) {
this.xNameField = xNameField;
return this;
}

public Target build() {
return new Target( this );
}
}
}
Loading