mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#1244 Fix problems with special word for FreeMarker in some cases
This commit is contained in:
parent
acdab55604
commit
3ebd09eec9
@ -760,8 +760,9 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
|||||||
return constantMappings;
|
return constantMappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<PropertyMapping>> getPropertyMappingsByParameter() {
|
public List<PropertyMapping> propertyMappingsByParameter(Parameter parameter) {
|
||||||
return mappingsByParameter;
|
// issues: #909 and #1244. FreeMarker has problem getting values from a map when the search key is size or value
|
||||||
|
return mappingsByParameter.get( parameter.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,8 +44,7 @@ public class Parameter extends ModelElement {
|
|||||||
private final boolean mappingContext;
|
private final boolean mappingContext;
|
||||||
|
|
||||||
private Parameter(String name, Type type, boolean mappingTarget, boolean targetType, boolean mappingContext) {
|
private Parameter(String name, Type type, boolean mappingTarget, boolean targetType, boolean mappingContext) {
|
||||||
// issue #909: FreeMarker doesn't like "values" as a parameter name
|
this.name = name;
|
||||||
this.name = "values".equals( name ) ? "values_" : name;
|
|
||||||
this.originalName = name;
|
this.originalName = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.mappingTarget = mappingTarget;
|
this.mappingTarget = mappingTarget;
|
||||||
|
@ -45,24 +45,24 @@
|
|||||||
</#list>
|
</#list>
|
||||||
<#if (sourceParameters?size > 1)>
|
<#if (sourceParameters?size > 1)>
|
||||||
<#list sourceParametersExcludingPrimitives as sourceParam>
|
<#list sourceParametersExcludingPrimitives as sourceParam>
|
||||||
<#if (propertyMappingsByParameter[sourceParam.name]?size > 0)>
|
<#if (propertyMappingsByParameter(sourceParam)?size > 0)>
|
||||||
if ( ${sourceParam.name} != null ) {
|
if ( ${sourceParam.name} != null ) {
|
||||||
<#list propertyMappingsByParameter[sourceParam.name] as propertyMapping>
|
<#list propertyMappingsByParameter(sourceParam) as propertyMapping>
|
||||||
<@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/>
|
<@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/>
|
||||||
</#list>
|
</#list>
|
||||||
}
|
}
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
<#list sourcePrimitiveParameters as sourceParam>
|
<#list sourcePrimitiveParameters as sourceParam>
|
||||||
<#if (propertyMappingsByParameter[sourceParam.name]?size > 0)>
|
<#if (propertyMappingsByParameter(sourceParam)?size > 0)>
|
||||||
<#list propertyMappingsByParameter[sourceParam.name] as propertyMapping>
|
<#list propertyMappingsByParameter(sourceParam) as propertyMapping>
|
||||||
<@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/>
|
<@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/>
|
||||||
</#list>
|
</#list>
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
<#else>
|
<#else>
|
||||||
<#if mapNullToDefault>if ( ${sourceParameters[0].name} != null ) {</#if>
|
<#if mapNullToDefault>if ( ${sourceParameters[0].name} != null ) {</#if>
|
||||||
<#list propertyMappingsByParameter[sourceParameters[0].name] as propertyMapping>
|
<#list propertyMappingsByParameter(sourceParameters[0]) as propertyMapping>
|
||||||
<@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/>
|
<@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/>
|
||||||
</#list>
|
</#list>
|
||||||
<#if mapNullToDefault>}</#if>
|
<#if mapNullToDefault>}</#if>
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._1244;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
|
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@IssueKey("1244")
|
||||||
|
@RunWith(AnnotationProcessorTestRunner.class)
|
||||||
|
@WithClasses( SizeMapper.class )
|
||||||
|
public class Issue1244Test {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void properlyCreatesMapperWithSizeAsParameterName() {
|
||||||
|
SizeMapper.SizeHolder sizeHolder = new SizeMapper.SizeHolder();
|
||||||
|
sizeHolder.setSize( "size" );
|
||||||
|
|
||||||
|
SizeMapper.SizeHolderDto dto = Mappers.getMapper( SizeMapper.class ).convert( sizeHolder );
|
||||||
|
assertThat( dto.getSize() ).isEqualTo( "size" );
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
|
||||||
|
* and/or other contributors as indicated by the @authors tag. See the
|
||||||
|
* copyright.txt file in the distribution for a full listing of all
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._1244;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SizeMapper {
|
||||||
|
|
||||||
|
SizeHolderDto convert(SizeHolder size);
|
||||||
|
|
||||||
|
SizeHolderDto convert(SizeHolder size, int test);
|
||||||
|
|
||||||
|
SizeHolderDto convertOther(SizeHolder sizeHolder, int size);
|
||||||
|
|
||||||
|
class SizeHolder {
|
||||||
|
private String size;
|
||||||
|
|
||||||
|
public String getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSize(String size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SizeHolderDto {
|
||||||
|
private String size;
|
||||||
|
|
||||||
|
public String getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSize(String size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -27,6 +27,10 @@ import org.mapstruct.Mapper;
|
|||||||
public interface ValuesMapper {
|
public interface ValuesMapper {
|
||||||
ValuesHolderDto convert(ValuesHolder values);
|
ValuesHolderDto convert(ValuesHolder values);
|
||||||
|
|
||||||
|
ValuesHolderDto convert(ValuesHolder values, int test);
|
||||||
|
|
||||||
|
ValuesHolderDto convertOther(ValuesHolder valuesHolder, int values);
|
||||||
|
|
||||||
class ValuesHolder {
|
class ValuesHolder {
|
||||||
private String values;
|
private String values;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user