diff --git a/core-jdk8/src/main/java/org/mapstruct/Mapping.java b/core-jdk8/src/main/java/org/mapstruct/Mapping.java
index d1c06e8b1..569d1d4dd 100644
--- a/core-jdk8/src/main/java/org/mapstruct/Mapping.java
+++ b/core-jdk8/src/main/java/org/mapstruct/Mapping.java
@@ -29,36 +29,41 @@ import java.util.Date;
/**
* Configures the mapping of one bean attribute or enum constant.
+ *
+ * The name of the mapped attribute or constant is to be specified via {@link #target()}. For mapped bean attributes it
+ * is assumed by default that the attribute has the same name in the source bean. Alternatively, one of
+ * {@link #source()}, {@link #expression()} or {@link #constant()} can be specified to define the property source.
+ *
+ * In addition, the attributes {@link #dateFormat()} and {@link #qualifiedBy()} may be used to further define the
+ * mapping.
*
* @author Gunnar Morling
*/
-@Retention( RetentionPolicy.SOURCE )
-@Target( ElementType.METHOD )
-@Repeatable( Mappings.class )
+@Repeatable(Mappings.class)
+@Retention(RetentionPolicy.SOURCE)
+@Target(ElementType.METHOD)
public @interface Mapping {
/**
- * The source to use for this Mapping. This can either be:
+ * The target name of the configured property as defined by the JavaBeans specification. If used to map an enum
+ * constant, the name of the constant member is to be given.
+ *
+ * @return The target name of the configured property or enum constant
+ */
+ String target();
+
+ /**
+ * The source to use for this mapping. This can either be:
*
* - The source name of the configured property as defined by the JavaBeans specification.
* - When used to map an enum constant, the name of the constant member is to be given.
*
- * Either this attribute or {@link #constant()} or {@link #expression()} may be specified for a given mapping, but
- * not two at the same time. If this attribute is given, the target property must be specified via
- * {@link #target()}.
+ * Either this attribute or {@link #constant()} or {@link #expression()} may be specified for a given mapping.
*
* @return The source name of the configured property or enum constant.
*/
String source() default "";
- /**
- * The target name of the configured property as defined by the JavaBeans specification. Defaults to the source name
- * if not given. If used to map an enum constant, the name of the constant member is to be given.
- *
- * @return The target name of the configured property or enum constant
- */
- String target() default "";
-
/**
* A format string as processable by {@link SimpleDateFormat} if the attribute is mapped from {@code String} to
* {@link Date} or vice-versa. Will be ignored for all other attribute types and when mapping enum constants.
@@ -72,32 +77,29 @@ public @interface Mapping {
* property is not of type {@code String}, the value will be converted by applying a matching conversion method or
* built-in conversion.
*
- * Either this attribute or {@link #source()} or {@link #expression()} may be specified for a given mapping, but not
- * two at the same time. If this attribute is given, the target property must be specified via {@link #target()}.
+ * Either this attribute or {@link #source()} or {@link #expression()} may be specified for a given mapping.
*
* @return A constant {@code String} constant specifying the value for the designated target property
*/
String constant() default "";
/**
- * An expression {@link String} based on which the specified target property is to be set.
- *
- * The format is determined by a type of expression. For instance:
+ * An expression {@link String} based on which the specified target property is to be set. The format is determined
+ * by a type of expression. For instance:
* {@code expression = "java(new org.example.TimeAndFormat( s.getTime(), s.getFormat() ))")} will insert the java
* expression in the designated {@link #target()} property.
*
- * Either this attribute or {@link #source()} or {@link #constant()} may be specified for a given mapping, but not
- * two at the same time. If this attribute is given, the target property must be specified via {@link #target()}.
+ * Either this attribute or {@link #source()} or {@link #constant()} may be specified for a given mapping.
*
* @return A constant {@code String} constant specifying the value for the designated target property
*/
String expression() default "";
/**
- * Whether the property specified via {@link #source()} or {@link #target()} should be ignored by the generated
- * mapping method or not. This can be useful when certain attributes should not be propagated from source or target
- * or when properties in the target object are populated using a decorator and thus would be reported as unmapped
- * target property by default.
+ * Whether the property specified via {@link #target()} should be ignored by the generated mapping method or not.
+ * This can be useful when certain attributes should not be propagated from source or target or when properties in
+ * the target object are populated using a decorator and thus would be reported as unmapped target property by
+ * default.
*
* @return {@code true} if the given property should be ignored, {@code false} otherwise
*/
@@ -105,9 +107,8 @@ public @interface Mapping {
/**
* A qualifier can be specified to aid the selection process of a suitable mapper. This is useful in case multiple
- * mappers (hand written of internal) qualify and result in an 'Ambiguous mapping methods found' error.
- *
- * A qualifier is a custom annotation and can be placed on either a hand written mapper class or a method.
+ * mapping methods (hand written or generated) qualify and thus would result in an 'Ambiguous mapping methods found'
+ * error. A qualifier is a custom annotation and can be placed on a hand written mapper class or a method.
*
* @return the qualifiers
*/
diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java
index 56e0e9623..c869e88a7 100644
--- a/core/src/main/java/org/mapstruct/Mapping.java
+++ b/core/src/main/java/org/mapstruct/Mapping.java
@@ -28,6 +28,13 @@ import java.util.Date;
/**
* Configures the mapping of one bean attribute or enum constant.
+ *
+ * The name of the mapped attribute or constant is to be specified via {@link #target()}. For mapped bean attributes it
+ * is assumed by default that the attribute has the same name in the source bean. Alternatively, one of
+ * {@link #source()}, {@link #expression()} or {@link #constant()} can be specified to define the property source.
+ *
+ * In addition, the attributes {@link #dateFormat()} and {@link #qualifiedBy()} may be used to further define the
+ * mapping.
*
* @author Gunnar Morling
*/
@@ -36,27 +43,25 @@ import java.util.Date;
public @interface Mapping {
/**
- * The source to use for this Mapping. This can either be:
+ * The target name of the configured property as defined by the JavaBeans specification. If used to map an enum
+ * constant, the name of the constant member is to be given.
+ *
+ * @return The target name of the configured property or enum constant
+ */
+ String target();
+
+ /**
+ * The source to use for this mapping. This can either be:
*
* - The source name of the configured property as defined by the JavaBeans specification.
* - When used to map an enum constant, the name of the constant member is to be given.
*
- * Either this attribute or {@link #constant()} or {@link #expression()} may be specified for a given mapping,
- * but not two at the same time. If this attribute is given, the target property must be specified via
- * {@link #target()}.
+ * Either this attribute or {@link #constant()} or {@link #expression()} may be specified for a given mapping.
*
* @return The source name of the configured property or enum constant.
*/
String source() default "";
- /**
- * The target name of the configured property as defined by the JavaBeans specification. Defaults to the source name
- * if not given. If used to map an enum constant, the name of the constant member is to be given.
- *
- * @return The target name of the configured property or enum constant
- */
- String target() default "";
-
/**
* A format string as processable by {@link SimpleDateFormat} if the attribute is mapped from {@code String} to
* {@link Date} or vice-versa. Will be ignored for all other attribute types and when mapping enum constants.
@@ -66,38 +71,33 @@ public @interface Mapping {
String dateFormat() default "";
/**
- * A constant {@link String} based on which the specified target property is to be set. If the designated
- * target property is not of type {@code String}, the value will be converted by applying a matching conversion
- * method or built-in conversion.
+ * A constant {@link String} based on which the specified target property is to be set. If the designated target
+ * property is not of type {@code String}, the value will be converted by applying a matching conversion method or
+ * built-in conversion.
*
- * Either this attribute or {@link #source()} or {@link #expression()} may be specified for a given mapping,
- * but not two at the same time. If this attribute is given, the target property must be specified via
- * {@link #target()}.
+ * Either this attribute or {@link #source()} or {@link #expression()} may be specified for a given mapping.
*
* @return A constant {@code String} constant specifying the value for the designated target property
*/
String constant() default "";
/**
- * An expression {@link String} based on which the specified target property is to be set.
- *
- * The format is determined by a type of expression. For instance:
+ * An expression {@link String} based on which the specified target property is to be set. The format is determined
+ * by a type of expression. For instance:
* {@code expression = "java(new org.example.TimeAndFormat( s.getTime(), s.getFormat() ))")} will insert the java
* expression in the designated {@link #target()} property.
*
- * Either this attribute or {@link #source()} or {@link #constant()} may be specified for a given mapping,
- * but not two at the same time. If this attribute is given, the target property must be specified via
- * {@link #target()}.
+ * Either this attribute or {@link #source()} or {@link #constant()} may be specified for a given mapping.
*
* @return A constant {@code String} constant specifying the value for the designated target property
*/
String expression() default "";
/**
- * Whether the property specified via {@link #source()} or {@link #target()} should be ignored by the generated
- * mapping method or not. This can be useful when certain attributes should not be propagated from source or target
- * or when properties in the target object are populated using a decorator and thus would be reported as unmapped
- * target property by default.
+ * Whether the property specified via {@link #target()} should be ignored by the generated mapping method or not.
+ * This can be useful when certain attributes should not be propagated from source or target or when properties in
+ * the target object are populated using a decorator and thus would be reported as unmapped target property by
+ * default.
*
* @return {@code true} if the given property should be ignored, {@code false} otherwise
*/
@@ -105,9 +105,8 @@ public @interface Mapping {
/**
* A qualifier can be specified to aid the selection process of a suitable mapper. This is useful in case multiple
- * mappers (hand written of internal) qualify and result in an 'Ambiguous mapping methods found' error.
- *
- * A qualifier is a custom annotation and can be placed on either a hand written mapper class or a method.
+ * mapping methods (hand written or generated) qualify and thus would result in an 'Ambiguous mapping methods found'
+ * error. A qualifier is a custom annotation and can be placed on a hand written mapper class or a method.
*
* @return the qualifiers
*/
diff --git a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java
index d7d99348d..2f56ece04 100644
--- a/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java
+++ b/processor/src/main/java/org/mapstruct/ap/model/BeanMappingMethod.java
@@ -305,8 +305,7 @@ public class BeanMappingMethod extends MappingMethod {
}
}
- else if ( mappedProperty.getConstant().isEmpty()
- && mappedProperty.getJavaExpression().isEmpty()
+ else if ( mappedProperty.getSourcePropertyName() != null
&& !hasSourceProperty( mappedProperty.getSourcePropertyName() ) ) {
ctx.getMessager().printMessage(
Diagnostic.Kind.ERROR,
diff --git a/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java
index 83af30c93..22e5f92b2 100644
--- a/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java
+++ b/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java
@@ -111,7 +111,8 @@ public class PropertyMapping extends ModelElement {
if ( mapping != null ) {
dateFormat = mapping.getDateFormat();
qualifiers = mapping.getQualifiers();
- sourcePropertyName = mapping.getSourcePropertyName();
+ sourcePropertyName =
+ mapping.getSourcePropertyName() == null ? targetPropertyName : mapping.getSourcePropertyName();
}
else {
sourcePropertyName = targetPropertyName;
@@ -121,18 +122,7 @@ public class PropertyMapping extends ModelElement {
// then iterate over source accessors (assuming the source is a bean)
for ( ExecutableElement sourceAccessor : sourceGetters ) {
-
- List sourceMappings = method.getMappings().get( sourcePropertyName );
- if ( method.getMappings().containsKey( sourcePropertyName ) ) {
- for ( Mapping sourceMapping : sourceMappings ) {
- boolean mapsToOtherTarget = !sourceMapping.getTargetName().equals( targetPropertyName );
- if ( Executables.getPropertyName( sourceAccessor ).equals( sourcePropertyName )
- && !mapsToOtherTarget ) {
- return getPropertyMapping( sourceAccessor, dateFormat, qualifiers );
- }
- }
- }
- else if ( Executables.getPropertyName( sourceAccessor ).equals( sourcePropertyName ) ) {
+ if ( Executables.getPropertyName( sourceAccessor ).equals( sourcePropertyName ) ) {
return getPropertyMapping( sourceAccessor, dateFormat, qualifiers );
}
}
diff --git a/processor/src/main/java/org/mapstruct/ap/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/model/source/Mapping.java
index 45deaf4ae..f64341429 100644
--- a/processor/src/main/java/org/mapstruct/ap/model/source/Mapping.java
+++ b/processor/src/main/java/org/mapstruct/ap/model/source/Mapping.java
@@ -24,7 +24,6 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import javax.annotation.processing.Messager;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
@@ -53,7 +52,7 @@ public class Mapping {
private final String javaExpression;
private final String targetName;
private final String dateFormat;
- private final List qualifiers;
+ private final List qualifiers;
private final boolean isIgnored;
private final AnnotationMirror mirror;
private final AnnotationValue sourceAnnotationValue;
@@ -85,18 +84,7 @@ public class Mapping {
mappingPrism.values.source()
);
- if ( mappingPrism.source().isEmpty() &&
- mappingPrism.constant().isEmpty() &&
- mappingPrism.expression().isEmpty() &&
- !mappingPrism.ignore() ) {
- messager.printMessage(
- Diagnostic.Kind.ERROR,
- "Either define a source, a constant or an expression in a Mapping",
- element
- );
- return null;
- }
- else if ( !mappingPrism.source().isEmpty() && !mappingPrism.constant().isEmpty() ) {
+ if ( !mappingPrism.source().isEmpty() && !mappingPrism.constant().isEmpty() ) {
messager.printMessage(
Diagnostic.Kind.ERROR,
"Source and constant are both defined in Mapping, either define a source or a constant",
@@ -120,10 +108,12 @@ public class Mapping {
);
return null;
}
+
+ String source = mappingPrism.source().isEmpty() ? null : mappingPrism.source();
return new Mapping(
- mappingPrism.source(),
+ source,
sourceNameParts != null ? sourceNameParts[0] : null,
- sourceNameParts != null ? sourceNameParts[1] : mappingPrism.source(),
+ sourceNameParts != null ? sourceNameParts[1] : source,
mappingPrism.constant(),
mappingPrism.expression(),
mappingPrism.target(),
@@ -156,8 +146,8 @@ public class Mapping {
}
//CHECKSTYLE:OFF
- private Mapping( String sourceName, String sourceParameterName, String sourcePropertyName, String constant,
- String expression, String targetName, String dateFormat, List qualifiers,
+ private Mapping(String sourceName, String sourceParameterName, String sourcePropertyName, String constant,
+ String expression, String targetName, String dateFormat, List qualifiers,
boolean isIgnored, AnnotationMirror mirror, AnnotationValue sourceAnnotationValue,
AnnotationValue targetAnnotationValue) {
this.sourceName = sourceName;
@@ -167,7 +157,7 @@ public class Mapping {
this.expression = expression;
Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( expression );
this.javaExpression = javaExpressionMatcher.matches() ? javaExpressionMatcher.group( 1 ).trim() : "";
- this.targetName = targetName.equals( "" ) ? sourceName : targetName;
+ this.targetName = targetName;
this.dateFormat = dateFormat;
this.qualifiers = qualifiers;
this.isIgnored = isIgnored;
@@ -246,12 +236,12 @@ public class Mapping {
// mapping can only be reversed if the source was not a constant nor an expression
if ( constant.isEmpty() && expression.isEmpty() ) {
reverse = new Mapping(
- targetName,
+ sourceName != null ? targetName : null,
null,
- targetName,
+ sourceName != null ? targetName : null,
constant,
expression,
- sourceName,
+ sourceName != null ? sourceName : targetName,
dateFormat,
qualifiers,
isIgnored,
diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToStringMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToStringMapper.java
index ae3d9b0bd..1fcaa2e43 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToStringMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToStringMapper.java
@@ -29,6 +29,6 @@ public interface CalendarToStringMapper {
CalendarToStringMapper INSTANCE = Mappers.getMapper( CalendarToStringMapper.class );
- @Mapping( source = "prop", dateFormat = "dd.MM.yyyy" )
+ @Mapping( target = "prop", dateFormat = "dd.MM.yyyy" )
StringProperty map( CalendarProperty source );
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToCalendarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToCalendarMapper.java
index b1a10ae3d..bc4b700c4 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToCalendarMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToCalendarMapper.java
@@ -29,6 +29,6 @@ public interface StringToCalendarMapper {
StringToCalendarMapper INSTANCE = Mappers.getMapper( StringToCalendarMapper.class );
- @Mapping( source = "prop", dateFormat = "dd.MM.yyyy" )
+ @Mapping( target = "prop", dateFormat = "dd.MM.yyyy" )
CalendarProperty map( StringProperty source);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToXmlGregCalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToXmlGregCalMapper.java
index 18c20c02d..55652c972 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToXmlGregCalMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToXmlGregCalMapper.java
@@ -31,7 +31,7 @@ public interface StringToXmlGregCalMapper {
XmlGregorianCalendarProperty map(StringProperty source);
- @Mapping(source = "prop", dateFormat = "dd.MM.yyyy")
+ @Mapping(target = "prop", dateFormat = "dd.MM.yyyy")
XmlGregorianCalendarProperty mapAndFormat(StringProperty source);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToStringMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToStringMapper.java
index f191788dc..fb04ec1ed 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToStringMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToStringMapper.java
@@ -31,7 +31,7 @@ public interface XmlGregCalToStringMapper {
StringProperty map(XmlGregorianCalendarProperty source);
- @Mapping(source = "prop", dateFormat = "dd.MM.yyyy")
+ @Mapping(target = "prop", dateFormat = "dd.MM.yyyy")
StringProperty mapAndFormat(XmlGregorianCalendarProperty source);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java
index d4db8bfd7..d71d29856 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java
@@ -21,10 +21,10 @@ package org.mapstruct.ap.test.conversion.date;
import java.util.Date;
import java.util.List;
+import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.IterableMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
-import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.factory.Mappers;
@Mapper
@@ -32,13 +32,15 @@ public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
- @Mapping(source = "date", dateFormat = "dd.MM.yyyy")
+ @Mapping(target = "date", dateFormat = "dd.MM.yyyy")
Target sourceToTarget(Source source);
+
@InheritInverseConfiguration
Source targetToSource(Target target);
@IterableMapping(dateFormat = "dd.MM.yyyy")
List stringListToDateList(List dates);
+
@InheritInverseConfiguration
List dateListToStringList(List strings);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java
index ef0e56365..648d9c600 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java
@@ -39,46 +39,46 @@ public interface SourceTargetMapper {
String LOCAL_TIME_FORMAT = "HH:mm";
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
- @Mappings( { @Mapping( source = "zonedDateTime", dateFormat = DATE_TIME_FORMAT ),
- @Mapping( source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT ),
- @Mapping( source = "localDate", dateFormat = LOCAL_DATE_FORMAT ),
- @Mapping( source = "localTime", dateFormat = LOCAL_TIME_FORMAT ) } )
+ @Mappings( { @Mapping( target = "zonedDateTime", dateFormat = DATE_TIME_FORMAT ),
+ @Mapping( target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT ),
+ @Mapping( target = "localDate", dateFormat = LOCAL_DATE_FORMAT ),
+ @Mapping( target = "localTime", dateFormat = LOCAL_TIME_FORMAT ) } )
Target sourceToTarget(Source source);
- @Mappings( { @Mapping( source = "zonedDateTime", dateFormat = DATE_TIME_FORMAT ),
- @Mapping( source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT ),
- @Mapping( source = "localDate", dateFormat = LOCAL_DATE_FORMAT ),
- @Mapping( source = "localTime", dateFormat = LOCAL_TIME_FORMAT ) } )
+ @Mappings( { @Mapping( target = "zonedDateTime", dateFormat = DATE_TIME_FORMAT ),
+ @Mapping( target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT ),
+ @Mapping( target = "localDate", dateFormat = LOCAL_DATE_FORMAT ),
+ @Mapping( target = "localTime", dateFormat = LOCAL_TIME_FORMAT ) } )
Target sourceToTargetDefaultMapping(Source source);
- @Mapping( source = "zonedDateTime", dateFormat = DATE_TIME_FORMAT )
+ @Mapping( target = "zonedDateTime", dateFormat = DATE_TIME_FORMAT )
Target sourceToTargetDateTimeMapped(Source source);
- @Mapping( source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT )
+ @Mapping( target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT )
Target sourceToTargetLocalDateTimeMapped(Source source);
- @Mapping( source = "localDate", dateFormat = LOCAL_DATE_FORMAT )
+ @Mapping( target = "localDate", dateFormat = LOCAL_DATE_FORMAT )
Target sourceToTargetLocalDateMapped(Source source);
- @Mapping( source = "localTime", dateFormat = LOCAL_TIME_FORMAT )
+ @Mapping( target = "localTime", dateFormat = LOCAL_TIME_FORMAT )
Target sourceToTargetLocalTimeMapped(Source source);
- @Mappings( { @Mapping( source = "zonedDateTime", dateFormat = DATE_TIME_FORMAT ),
- @Mapping( source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT ),
- @Mapping( source = "localDate", dateFormat = LOCAL_DATE_FORMAT ),
- @Mapping( source = "localTime", dateFormat = LOCAL_TIME_FORMAT ) } )
+ @Mappings( { @Mapping( target = "zonedDateTime", dateFormat = DATE_TIME_FORMAT ),
+ @Mapping( target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT ),
+ @Mapping( target = "localDate", dateFormat = LOCAL_DATE_FORMAT ),
+ @Mapping( target = "localTime", dateFormat = LOCAL_TIME_FORMAT ) } )
Source targetToSource(Target target);
- @Mapping( source = "zonedDateTime", dateFormat = DATE_TIME_FORMAT )
+ @Mapping( target = "zonedDateTime", dateFormat = DATE_TIME_FORMAT )
Source targetToSourceDateTimeMapped(Target target);
- @Mapping( source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT )
+ @Mapping( target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT )
Source targetToSourceLocalDateTimeMapped(Target target);
- @Mapping( source = "localDate", dateFormat = LOCAL_DATE_FORMAT )
+ @Mapping( target = "localDate", dateFormat = LOCAL_DATE_FORMAT )
Source targetToSourceLocalDateMapped(Target target);
- @Mapping( source = "localTime", dateFormat = LOCAL_TIME_FORMAT )
+ @Mapping( target = "localTime", dateFormat = LOCAL_TIME_FORMAT )
Source targetToSourceLocalTimeMapped(Target target);
@InheritInverseConfiguration( name = "sourceToTarget" )
diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java
index 86fbc7569..1aea8504c 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java
@@ -38,47 +38,46 @@ public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
@Mappings({
- @Mapping(source = "dateTime", dateFormat = DATE_TIME_FORMAT),
- @Mapping(source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT),
- @Mapping(source = "localDate", dateFormat = LOCAL_DATE_FORMAT),
- @Mapping(source = "localTime", dateFormat = LOCAL_TIME_FORMAT)
+ @Mapping(target = "dateTime", dateFormat = DATE_TIME_FORMAT),
+ @Mapping(target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT),
+ @Mapping(target = "localDate", dateFormat = LOCAL_DATE_FORMAT),
+ @Mapping(target = "localTime", dateFormat = LOCAL_TIME_FORMAT)
})
Target sourceToTarget(Source source);
@InheritInverseConfiguration( name = "targetToSource" ) // TODO: FIXME
Target sourceToTargetDefaultMapping(Source source);
- @Mapping(source = "dateTime", dateFormat = DATE_TIME_FORMAT)
+ @Mapping(target = "dateTime", dateFormat = DATE_TIME_FORMAT)
Target sourceToTargetDateTimeMapped(Source source);
- @Mapping(source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT)
+ @Mapping(target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT)
Target sourceToTargetLocalDateTimeMapped(Source source);
- @Mapping(source = "localDate", dateFormat = LOCAL_DATE_FORMAT)
+ @Mapping(target = "localDate", dateFormat = LOCAL_DATE_FORMAT)
Target sourceToTargetLocalDateMapped(Source source);
- @Mapping(source = "localTime", dateFormat = LOCAL_TIME_FORMAT)
+ @Mapping(target = "localTime", dateFormat = LOCAL_TIME_FORMAT)
Target sourceToTargetLocalTimeMapped(Source source);
-
@Mappings({
- @Mapping(source = "dateTime", dateFormat = DATE_TIME_FORMAT),
- @Mapping(source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT),
- @Mapping(source = "localDate", dateFormat = LOCAL_DATE_FORMAT),
- @Mapping(source = "localTime", dateFormat = LOCAL_TIME_FORMAT)
+ @Mapping(target = "dateTime", dateFormat = DATE_TIME_FORMAT),
+ @Mapping(target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT),
+ @Mapping(target = "localDate", dateFormat = LOCAL_DATE_FORMAT),
+ @Mapping(target = "localTime", dateFormat = LOCAL_TIME_FORMAT)
})
Source targetToSource(Target target);
- @Mapping(source = "dateTime", dateFormat = DATE_TIME_FORMAT)
+ @Mapping(target = "dateTime", dateFormat = DATE_TIME_FORMAT)
Source targetToSourceDateTimeMapped(Target target);
- @Mapping(source = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT)
+ @Mapping(target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT)
Source targetToSourceLocalDateTimeMapped(Target target);
- @Mapping(source = "localDate", dateFormat = LOCAL_DATE_FORMAT)
+ @Mapping(target = "localDate", dateFormat = LOCAL_DATE_FORMAT)
Source targetToSourceLocalDateMapped(Target target);
- @Mapping(source = "localTime", dateFormat = LOCAL_TIME_FORMAT)
+ @Mapping(target = "localTime", dateFormat = LOCAL_TIME_FORMAT)
Source targetToSourceLocalTimeMapped(Target target);
@InheritInverseConfiguration( name = "sourceToTarget" ) // TODO: FIXME
diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/SourceTargetMapper.java
index 02448cc7c..0a9cbd629 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/SourceTargetMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/SourceTargetMapper.java
@@ -27,7 +27,7 @@ public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
- @Mapping( source = "object", ignore = true )
+ @Mapping( target = "object", ignore = true )
Target sourceToTarget(Source source);
Source targetToSource(Target target);
diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java
index 4fcb2a47a..2e071e93b 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java
@@ -18,10 +18,9 @@
*/
package org.mapstruct.ap.test.ignore;
+import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
-import org.mapstruct.Mappings;
-import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.factory.Mappers;
@Mapper
@@ -29,11 +28,9 @@ public interface AnimalMapper {
AnimalMapper INSTANCE = Mappers.getMapper( AnimalMapper.class );
- @Mappings({
- @Mapping(source = "size", ignore = true),
- @Mapping(target = "age", ignore = true)
- })
+ @Mapping(target = "age", ignore = true)
AnimalDto animalToDto(Animal animal);
+
@InheritInverseConfiguration
Animal animalDtoToAnimal(AnimalDto animalDto);
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java
index 2c823910c..54e15190b 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java
@@ -18,14 +18,14 @@
*/
package org.mapstruct.ap.test.ignore;
+import static org.fest.assertions.Assertions.assertThat;
+
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 static org.fest.assertions.Assertions.assertThat;
-
/**
* Test for ignoring properties during the mapping.
*
@@ -35,18 +35,6 @@ import static org.fest.assertions.Assertions.assertThat;
@RunWith(AnnotationProcessorTestRunner.class)
public class IgnorePropertyTest {
- @Test
- @IssueKey("72")
- public void shouldNotPropagateIgnoredPropertyGivenViaSourceAttribute() {
- Animal animal = new Animal( "Bruno", 100, 23 );
-
- AnimalDto animalDto = AnimalMapper.INSTANCE.animalToDto( animal );
-
- assertThat( animalDto ).isNotNull();
- assertThat( animalDto.getName() ).isEqualTo( "Bruno" );
- assertThat( animalDto.getSize() ).isNull();
- }
-
@Test
@IssueKey("72")
public void shouldNotPropagateIgnoredPropertyGivenViaTargetAttribute() {
diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMapper.java
index 7cef559a0..386aa91fd 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMapper.java
@@ -18,12 +18,12 @@
*/
package org.mapstruct.ap.test.selection.qualifier;
-import org.mapstruct.ap.test.selection.qualifier.bean.GermanRelease;
-import org.mapstruct.ap.test.selection.qualifier.bean.OriginalRelease;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.ap.test.selection.qualifier.annotation.NonQualifierAnnotated;
+import org.mapstruct.ap.test.selection.qualifier.bean.GermanRelease;
+import org.mapstruct.ap.test.selection.qualifier.bean.OriginalRelease;
import org.mapstruct.ap.test.selection.qualifier.handwritten.SomeOtherMapper;
import org.mapstruct.ap.test.selection.qualifier.handwritten.YetAnotherMapper;
import org.mapstruct.factory.Mappers;
@@ -38,7 +38,7 @@ public interface ErroneousMapper {
ErroneousMapper INSTANCE = Mappers.getMapper( ErroneousMapper.class );
@Mappings( {
- @Mapping( source = "title", qualifiedBy = { NonQualifierAnnotated.class } ), } )
+ @Mapping( target = "title", qualifiedBy = { NonQualifierAnnotated.class } ), } )
GermanRelease toGerman( OriginalRelease movies );
}
diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieMapper.java
index bf1bc9b61..1e2448530 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieMapper.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieMapper.java
@@ -18,15 +18,15 @@
*/
package org.mapstruct.ap.test.selection.qualifier;
-import org.mapstruct.ap.test.selection.qualifier.bean.GermanRelease;
-import org.mapstruct.ap.test.selection.qualifier.bean.OriginalRelease;
-import org.mapstruct.ap.test.selection.qualifier.handwritten.Titles;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.ap.test.selection.qualifier.annotation.EnglishToGerman;
import org.mapstruct.ap.test.selection.qualifier.annotation.TitleTranslator;
+import org.mapstruct.ap.test.selection.qualifier.bean.GermanRelease;
+import org.mapstruct.ap.test.selection.qualifier.bean.OriginalRelease;
import org.mapstruct.ap.test.selection.qualifier.handwritten.SomeOtherMapper;
+import org.mapstruct.ap.test.selection.qualifier.handwritten.Titles;
import org.mapstruct.factory.Mappers;
/**
@@ -39,7 +39,7 @@ public interface MovieMapper {
MovieMapper INSTANCE = Mappers.getMapper( MovieMapper.class );
@Mappings( {
- @Mapping( source = "title", qualifiedBy = { TitleTranslator.class, EnglishToGerman.class } ),
+ @Mapping( target = "title", qualifiedBy = { TitleTranslator.class, EnglishToGerman.class } )
} )
GermanRelease toGerman( OriginalRelease movies );
diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java
index 06ff188a9..8a6140c2b 100644
--- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java
+++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java
@@ -18,10 +18,13 @@
*/
package org.mapstruct.ap.test.source.constants;
+import static org.fest.assertions.Assertions.assertThat;
+
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
+
import javax.tools.Diagnostic.Kind;
import org.junit.Test;
@@ -33,8 +36,6 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
-import static org.fest.assertions.Assertions.assertThat;
-
/**
* @author Sjaak Derksen
*/
@@ -159,31 +160,6 @@ public class SourceConstantsTest {
public void errorOnSourceAndExpression() throws ParseException {
}
- @Test
- @IssueKey("187")
- @WithClasses({
- Source.class,
- Target.class,
- ErroneousMapper2.class,
- StringListMapper.class
- })
- @ExpectedCompilationOutcome(
- value = CompilationResult.FAILED,
- diagnostics = {
- @Diagnostic(type = ErroneousMapper2.class,
- kind = Kind.ERROR,
- line = 41,
- messageRegExp = "Either define a source, a constant or an expression in a Mapping"),
- @Diagnostic(type = ErroneousMapper2.class,
- kind = Kind.WARNING,
- line = 41,
- messageRegExp = "Unmapped target property: \"integerConstant\"")
- }
- )
- public void errorOnNeitherSourceNorExpression() throws ParseException {
- }
-
-
@Test
@IssueKey("255")
@WithClasses({