NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
Maven Central
Maven Central, #827 by repository stars
An annotation processor for generating type-safe bean mappers
Latest stable
1.6.3
Last release 4 months ago
27 Jun 2026
Release timing varies
gaps range from 9 days to 1.2 years
Most releases are documented
notes for 16 of 18 stable releases
Nothing withdrawn
no release was ever pulled
13 years old
49 releases · first in 2013
Drag across the ruler to compare, or tap a release to open it.
Make URLToStringConversion generate URI.create(String).toURL() instead of the deprecated new URL(String)
@NonNull, @Nullable, @NullMarked and @NullUnmarked from org.jspecify.annotations to control null check generation:
@NonNull skips null checks; target @NonNull always adds them@NonNull source parameters skip the method-level null guard@NonNull source on collection-typed property mappings skips the wrapping null guardIterable, Map, Stream, arrays) honor JSpecify on their source parameter@NonNull mapping-method return type implies NullValueMappingStrategy.RETURN_DEFAULT semantics across bean, iterable, map and stream mapping methods@NullMarked / @NullUnmarked scope is resolved by walking method → class → outer class → package@NonNull constructor parameter without a defaultValuemapstruct.disableJSpecify compiler optionURI to String built-in conversions (#4018)ClassAccessibility enum to control the declared accessibility of generated mappers (#2513)SET_TO_NULL for overloaded target methods, requiring a cast (#3949)URLToStringConversion generate URI.create(String).toURL() instead of the deprecated new URL(String) (#4041)SET_TO_DEFAULT when the target has no accessible no-args constructor (#4060)new expressions in generated code (#4045)LinkedHashMap and LinkedHashSet when targeting SequencedSet and SequencedMap (#3990)Type.describe() (#3991)Optional target not using the static builder factory method (#4046)ZonedDateTime or OffsetDateTime to LocalDateTime or Instant (#4027)SECURITY.md and .github/INCIDENT_RESPONSE.mdjava-kotlin to noneCustomImportOrder (#4024)fail in assertCheckstyleRulesNumber API usage from testsStandardCharsets.UTF_8 in testsModifiableURLClassLoader test util (#4052)LauncherDiscoveryListener with CompilerLauncherInterceptor (#4051)ParenPad for ENUM_CONSTANT_DEF via Checkstyle (#4075)JavaFileAssert#hasSameMapperContent to include file information in the diff (#4063)Visitor6 usages to Visitor8TypeFactory.getTypeParameters (#4020)ValueMappingMethod by removing inversion (#4007)keySet() invocation (#3989)Fields (#4010)GeneratedTypeBuilder (#4009)equals of Type (#3995)isDefaultMethod (#4053)Your coding agent can read these notes before it upgrades. Set up the MCP server →
Support for Java 21 Sequenced Collections
java.util.Optional mapping (#674) - MapStruct now fully supports Optional as both source and target types:
Optional to Optional - Both source and target wrapped in OptionalOptional to Non-Optional - Unwrapping Optional valuesOptional to Optional - Wrapping values in OptionalOptional properties in beans with automatic presence checks. Note, there is no null check done for Optional properties.org.jetbrains.kotlin:kotlin-metadata-jvm.
@IgnoredBuilder and has a constructor with parameters,
it will be treated as a potential builder.
Builders through static methods on the type have a precedence.@SubclassMapping mapping (#3821) - Available on @BeanMapping, @Mapper and @MappingConfig.NullValuePropertyMappingStrategy#CLEAR for clearing Collection and Map properties when updating a bean (#1830)@AnnotatedWith on decorators (#3659)ignoreUnmappedSourceProperties entries (#3906)Optional with Optional.empty instead of null (#3852)String to Number as lossy conversion (#3848)@TargetPropertyName failing for nested update mappings (#3809)mapstruct.disableLifecycleOverloadDeduplicateSelector.@Context (#3711)NullValuePropertyMappingStrategy.IGNORE for collections / maps without setters (#3806)NullValuePropertyMappingStrategy.SET_TO_DEFAULT initializes empty collection/map when target is null (#3884)Override (#3905)With this change, if the target bean does not have any target properties, a warning will be shown. This is like this to avoid potential mistakes by users, where they might think that the target bean has properties, but it does not.
ignoreUnmappedSourceProperties entries (#3906)With this change, if the ignoreUnmappedSourceProperties configuration contains properties that are actually mapped, a warning or compiler error will be shown.
The unmappedSourcePolicy is used to determine whether a warning, or an error is shown.
Optional with Optional.empty instead of null (#3852)With this change, if the target Optional property is null, it will be initialized with Optional.empty() instead of null.
String to Number as lossy conversion (#3848)With this change, if the source String property is mapped to a Number property, a warning will be shown.
This is similar to what is happening when mapping long to int, etc.
The typeConversionPolicy ReportingPolicy is used to determine whether a warning, error or ignore is shown.
Redundant if condition in Java record mapping with RETURN_DEFAULT strategy
RETURN_DEFAULT strategy (#3747)java.time.LocalDate when mapping source LocalDateTime to target LocalDate (#3732)Regression from 1.6.1: ClassCastException when using records
Use Java LinkedHashSet and LinkedHashMap new factory method with known capacity when on Java 19 or later
LinkedHashSet and LinkedHashMap new factory method with known capacity when on Java 19 or later (#3113)SubclassMapping: generic vs raw types (#3668)InheritInverseConfiguration with nested target properties and reversing target = "." (#3670)@AfterMapping methods are called twice when using target with builder (#3678)@AfterMapping method with Builder and TargetObject (#3703)Prior to this fix @Mapping(target = "myProperty", ignore = true) was being ignored when using @InheritInverseConfiguration.
e.g.
@Mapper
public interface ModelMapper {
@Mapping(target = "creationDate", ignore = true)
Entity toEntity(Model model);
@InheritInverseConfiguration
Model toModel(Entity entity);
}
In the example above prior 1.6.1 the Model toModel(Entity entity) was going to map the id property. In order to keep that behavior you'll need to explicitly do the mapping for it.
@Mapper
public interface ModelMappe {
@Mapping(target = "creationDate", ignore = true) // NOTE: Handled by JPA.
Entity toEntity(Model model);
@InheritInverseConfiguration
@Mapping(target = "creationDate", source = "creationDate") // Allow reading from Entity
Model toModel(Entity entity);
}
### Previous Release Notes * 1.6.0.RC1 * 1.6.0.Beta2 * 1.6.0.Beta1
Breaking change: (#3574) - This reverts #2560, because we've decided that @BeanMapping(ignoreByDefault = true) should only be applied to target proper…
@BeanMapping(ignoreByDefault = true) should only be applied to target properties and not to source properties.
Source properties are ignored anyway, the BeanMapping#unmappedSourcePolicy should be used to control what should happen with unmapped source policy@SubclassMapping not working with @BeanMapping#ignoreUnmappedSourceProperties (#3609)unmappedSourcePolicy default value (#3635)In 1.6, support for presence checks on source parameters has been added.
This means that even if you want to map a source parameter directly to some target property the new @SourceParameterCondition or @Condition(appliesTo = ConditionStrategy.SOURCE_PARAMETERS) should be used.
e.g.
If we had the following in 1.5:
@Mapper
public interface OrderMapper {
@Mapping(source = "dto", target = "customer", conditionQualifiedByName = "mapCustomerFromOrder")
Order map(OrderDTO dto);
@Condition
@Named("mapCustomerFromOrder")
default boolean mapCustomerFromOrder(OrderDTO dto) {
return dto != null && dto.getCustomerName() != null;
}
}
Then MapStruct would generate
public class OrderMapperImpl implements OrderMapper {
@Override
public Order map(OrderDTO dto) {
if ( dto == null ) {
return null;
}
Order order = new Order();
if ( mapCustomerFromOrder( dto ) ) {
order.setCustomer( orderDtoToCustomer( orderDTO ) );
}
return order;
}
}
In order for the same to be generated in 1.6, the mapper needs to look like this:
@Mapper
public interface OrderMapper {
@Mapping(source = "dto", target = "customer", conditionQualifiedByName = "mapCustomerFromOrder")
Order map(OrderDTO dto);
@SourceParameterCondition
@Named("mapCustomerFromOrder")
default boolean mapCustomerFromOrder(OrderDTO dto) {
return dto != null && dto.getCustomerName() != null;
}
}
Support conditional mapping for source parameters (#2610, #3459, #3270)
@SourcePropertyName to handle a property name of the source object (#3323) - Currently only applicable for @Condition methodstarget = "." using expression (#3485)@Condition cannot be used only with @Context parameters (#3561)@Condition treated as ambiguous mapping for methods returning Boolean/boolean (#3565)Mapping#expression and Mapping#conditionalQualifiedBy(Name) should lead to compile error (#3413)Mapping#ignoreByDefault is inherited in nested mappings in documentation (#3577)@SuperBuilder is supported (#3524)Breaking change: Mapping from Map to Bean
@TargetPropertyName can be used to access the target property name to conditional and mapping methods@AnnotateWith. If a method is annotated with @Deprecated it is automatically copied into the generated code.nullValueIterableMappingStrategy and nullValueMapMappingStrategy (#2953) - The different strategies can be configured using mapstruct.nullValueIterableMappingStrategy and mapstruct.nullValueMapMappingStrategy respectivelySubclassMapping annotated methods (#3119)AdditionalSupportedOptionsProvider that can be used to defined the supported options for a custom SPI. The additional options cannot start with mapstruct.@JavadocEnum and Integer (#2963)Locale and String (#3172)java.time.LocalDate and java.time.LocalDateTime (#3199)@AnnotateWith(value = Service.class, elements = @AnnotateWith.Element(strings = "cakeMapperV2"))@ValueMapping (#3037)CollectionMappingStrategy#TARGET_IMMUTABLE (#2952)SubclassMapping (#3202)@InheritConfiguration for @SubclassMapping in methods with identical signature (#3125)subclassExhaustiveStrategy when source is a sealed class and all subtypes are specified (#3054)String type for @TargetPropertyName (#2863)@BeforeMapping with @TargetType the type being build@AfterMapping with @TargetType the type being build@AfterMapping with @MappingTarget the type being build@Default on Java Record's constructor isn't respected (#3231)InjectionStrategy.SETTER (#3229)BeanMapping#unmappedSourcePolicy (#3309)Iterable to Collection (#3376)@TargetType on Collection fails to compile (#2901)@SubclassMapping (#3174)@BeanMapping(ignoreByDefault = true) does not work for constructor properties (#3158)@ValueMapping strips spaces from source (#3153)defaultExpression does not work when mapping a collection of custom types (#3159)NullPointerException when ignoring target '.' (#3238) - There is now a compilation error instead of an error in the processorNullValuePropertyMappingStrategy.IGNORE does not ignore target collection even when source one is null (only when collectionMappingStrategy = CollectionMappingStrategy.TARGET_IMMUTABLE) (#3104)@SubclassMapping not working with @Mapping nested properties and target all (#3126)default and static methods in @MapperConfig (#3296)CollectionMappingStrategy.ADDER_PREFERRED fails (#3310)@InheritConfiguration (#3361)In 1.5 we added support for mapping a map to a bean by implicitly mapping all the properties from the target bean by accessing them from the map. However, this lead to some problems in multi mapping methods. Therefore, in this release we tightened up a bit and in multi source mapping methods the Map will not be considered when doing implicit mappings.
e.g.
@Mapper
public interface CarMapper {
// This method is going to implicitly map all the target properties from the map
Target map(Map<String, Object> map);
// This method is not going to use the map for implicit mappings.
// Only the name will be mapped from the map (since it has been defined like that
@Mapping(target = "name", source = "map.name")
Target map(Source source, Map<String, Object> map)
}
@BeanMapping inheritanceAll, except resultType and ignoredUnmappedSourceProperties attributes of @BeanMapping have been made to consistently be passed down to the generated nested methods. This means that if you were relying on some buggy behavior it might no longer work.
e.g. BeanMapping#ignoreByDefault was not being passed down properly, i.e. implicit mapping was being done for nested properties. This has been fixed. If you want to implicitly map nested mappings then you'll have to define your own mapper appropriatelly.
@Mapper
interface MyMapper {
@BeanMapping( ignoreByDefault = true )
@Mapping( source = "sub", target = "target" )
Target map( Source source );
}
needs to be replaced with
@Mapper
interface MyMapper {
@BeanMapping( ignoreByDefault = true )
@Mapping( source = "sub", target = "target" )
Target map( Source source );
// this is the mapping `source = "sub"` and `target = "target"`
// redefined to get rid of the `ignoreByDefault=true`, because this property is inherited
SubTarget subSourceToSubTarget( SubSource subSource );
}
After the request from the community we have enabled sponsoring for the project. See #2340 for how you can sponsor us if you want to.
Add support for Jakarta XML Binding
BeanMappingOptions#ignoreUnmappedSourceProperties are not inherited via @InheritConfiguration (#3248) - Regression from 1.5.3Support for Jakarta @ApplicationScoped is missing
@ApplicationScoped is missing (#2950)throws clauses when mapping enum with checked exceptions (#3110)Mapping annotations for nested objects (worked with 1.5.2) (#3057)BeanMapping#mappingControl (#3040)<THROW_EXCEPTION> in the reference guide (#3112)Generic @AfterMapping does not consider @MappingTarget properly in 1.5
@AfterMapping does not consider @MappingTarget properly in 1.5 (#3036)@AfterMapping is not called (#2955)SubclassMapping doesn't honour mappingControl (#3018)BigDecimal to primitive double wrong with 1.5.2 (#2913)SubclassMapping stackoverflow exception (#2825)Optional wrapping pattern broken in 1.5.2.Final (#2925)@Conditional and collection (#2937)try-catch block (#2839)@TargetType as a parameter for @Condition causes NPE during compiling (#2882)BeanMapping#ignoreByDefault (#2929)Add support for Java Text Blocks in expressions
SubclassExhaustiveStrategy.RUNTIME_EXCEPTION option does not work if the superclass has a non-empty constructor #2891NullPointerException when reporting errors for non Mappers
NullPointerException when reporting errors for non Mappers (#2867)Compilation error due to missing import with nested classes
@Condition on a presence check for a generic wrapper (#2795)conditionExpression and expression are used together (#2794)@BeforeMapping on a used mapper (#2807)Add compiler check for unimplemented methods for lifecycle @BeforeMapping / @AfterMapping methods
@BeforeMapping / @AfterMapping methods (#2674)@DecoratedWith does not work with incremental compilation in Gradle 7.3 (#2682)@InheritInverseConfiguration with @SubclassMapping(s) (#2696)qualifiedByName, uses and method chaining (#2538) - In 1.4 we strengthened the check for qualified methods and reported an error if there was no applicable qualifier. This strengthening led to 2-step mappings not to work properly when only one of the steps is qualified. With this issue it is now possible to use 2-step mappings with only one of the steps being qualified.javax.annotation.processing.Generated in modular Java does not seem to work (#2629)@Condition docs out of sync (#2689)NullValueMappingStrategy for collections and maps (#2687)@AfterMapping / @BeforeMapping methods (#2719)We'd like to thank all the contributors who worked on this release!
Support for Type-Refinement mapping (or Downcast Mapping) (#131, #366, #2438)
NullValueMappingStrategy option to map collections/maps, but not beans (#2351)@MappingTarget) when the source object is null (#1752) - See Behaviour Changes@Mapper annotation (#2225)CaseEnumTransformationStrategy (#2525)URL and String (#2552)unmappedSourcePolicy annotation processor argument (#2555)ZonedDateTime field mapping regression (#2530)unmappedSourcePolicy and implicit source mapping (#2537)ReverseConversion should maintain RequiredHelperMethods (#2544)BeanMapping#ignoreByDefault interaction with unmappedSourcePolicy (#2560)Stream to Array (#2614)Map to Bean (#2624)@Condition not working when the source in the Mapping is the source parameter (#2666)defaultValue (#2636)Prior to this release update mappings with a return type returned null when the source parameter was null. However, this is not what a user expects (see https://github.com/mapstruct/mapstruct/issues/1752).
With this release methods like
Car updateCar(CarDto source, @MappingTarget Car car);
will always return the @MappingTarget method, irregardless of what the source is.
[Breaking Change] Retain iteration order for Sorted(Map|Set) values (#2303) - In order to keep the previous behaviour and use Hash(Map|Set) use an @Ob…
Map<String, ???> to Bean (#1075)Iterable<?> object to an object instead of collection (#607)String <-> StringBuilder (#597)UUID to a String (#2391)componentModel in MappingConstants.ComponentModel (#2255)INSTANCE (if it exists) in mapper references when using the default component model (#2277)@ObjectFactoryunmappedTargetPolicy for @BeanMapping (#2132)java.time.format.DateTimeFormatter instances final members (#2329)BeanMapping#ignoreUnmappedSourceProperties were ignored, now there will be a compile error as it is most likely a mistake. To fix the error the unknown properties should be removed from BeanMapping#ignoreUnmappedSourcePropertiesdefaultExpression lead to unnecessary null checks and unexpected code (#2023)@ValueMapping string-to-enum mapping results in no cases in switch (#2350)@InheritInverseConfiguration (#2356)Enum[] to String, the mapping processor throws NPE (#2439)@Mapping (#2368)The introduction of the mapping from Map<String, ???> to Bean might have lead to some changes in how currently explicitly mapped maps are mapped. Some known changes are:
Relax strictness for Mapping#qualifiedByName and Mapping#qualifier for collection mappings (#2324, #2346)
Mapping#qualifiedByName and Mapping#qualifier for collection mappings (#2324, #2346)Optional<T> mapping (#2295)@InheritInverseConfiguration and @Mapping(target:"bean.childProperty", ignore=true) do not play together (#2278)@InheritConfiguration defines a mapping for a sub-field (#2318)@Default annotation as of 1.4.X (#2258)@MapperConfig annotation in documentation (#2293)@InheritConfiguration is broken when using multiple source parameters of the same type
@InheritConfiguration is broken when using multiple source parameters of the same type (#2221)@Mapping with defaultValue and method argument where is missing source does nothing (#2220)-Djps.track.ap.dependencies=false. More info about this is in IDEA-250718@Mapping needs to define source parameter with defaultValue if you have two arguments in 1.4.0.Final (#2214)For full upgrade instructions please read the release notes for the previous 1.4 releases:
For full upgrade instructions please read the release notes for the previous 1.4 releases:
Support custom unexpected enum constant exception for Value (Enum) Mapping
@since 1.4 to new interfaces (#2167)Improve the error message when using @Qualifier in 2 step mapping methods
@Qualifier in 2 step mapping methods (#2135)@Default to overrule potentially existing parameterless default constructor. (#2150) - With this we actually changed the rules for selection a constructor. Now the following is done:
@Default (from any package) has highest precedenceNullPointerException when using only Mapping#target in mapping inheritance (#2139)@BeanMapping(ignoreByDefault = true) in combination with @Mapping(target = "."). This is now not allowedImprove the error message when using @Qualifier in 2 step mapping methods
@Qualifier in 2 step mapping methods (#2135)@MappingConfig inherited reverse mapping (#1844)@BeanMapping#resultType does not work with nested mappings (#2133)ALWAYS and using constructor for instantiating mapping target (#2131)Make use of constructor arguments when instantiating mapping targets (#73) - Also supports Java 14 records and Kotlin Data classes
String and Enum (#1557)@Mapping in meta annotation (#807)EnumTransformationStrategy and EnumNamingStrategy SPIs (#796, #1220, #1789, #1667 and PRs: #2089, #2100)See release announcement for more information.
mapstruct.verbose=truejava.lang.Object as intermediate result in 2 step mappings (#1698)@MapperConfig (#1435)java.time.LocalDateTime and javax.xml.datatype.XMLGregorianCalendar (#1791)@BeanMapping(ignoreByDefault=true) in @MapperConfig not passed to mapping method (#1933)unmappedSourcePolicy set to ERROR leads to a nested Bean issue (#1881)<ANY_REMAING> and <ANY_UNMAPPED> not ignored when inverting Value mapping (#1936)defaultExpression not being applied when source property not specified explicitly (#1966)@DecoratedWith (#1773)org.mapstruct.* annotations (#166)@InheritInverseConfiguration doesn't pickup ignore mapping (#1983)SourceReference (#1745)model.source should reflect source only and not (intermediate) creation state (#1867)BeanMapping and Source/TargetReferences (common base class) (PR #1903)@MapperConfig, @Mapper, @BeanMapping, @Mapping, @IterableMapping and @MapMapping (#1998)JaxbMapper from integration tests (#724) - Not needed anymore, since MapStruct can work without it. No changes for usersTypeFactory (#1883)SourceMethod (#1897)org.mapstruct.ap.internal.util.Filters (#1895)TargetTypeSelector, ValueMapping, MethodRetrievalProcessor (#1889)MapperConfiguration.getBuilderPrism from Optional<BuilderPrism> to BuilderPrism (#1911)JavaStreamConstants (#1944)Map.computeIfAbsent in NestedTargetPropertyMappingHolder (#1951)TargetReference refactorings (#2069)Before when doing 2 step mappings MapStruct was forgetting the qualifiers and could select methods with other qualifiers. This is unexpected and has been changed so that qualifiers are always used.
See Issue #1714 and PR #1739 for more information.
Before this release it was possible to use @Mapping for mapping enums. This is no longer possible and @ValueMapping should be used before. There was a warning before, so if you don't have that in your build then you don't need to do anything.
We'd like to thank all the contributors who worked on this release!
@AfterMapping methods with non unique parameters (#1457) - Stricter matching for lifecycle methods / non-unique parameters In case a lifecycle method
@AfterMapping methods with non unique parameters (#1457) - Stricter matching for lifecycle methods / non-unique parameters
In case a lifecycle method has multiple matching parameters (e. g. same type)
all parameter names must match exactly with the ones from the mapping method,
otherwise the lifecycle method will not be used and a warning will be shown.Builder#disableBuilder (#1661)ReportingPolicy.ERROR on Unmapped Source Properties (#1772)EnumSet (#1797)nullValuePropertyMappingStrategy when inherited (#1790)@Context not yielding Impl classes in Java11 (#1904)builderCreationMethod in custom builder provider causes NullPointerException (#1801)NullValueMappingStrategy.RETURN_DEFAULT (#1784)This contains only changes between 1.3.0.Beta2 and 1.3.0.Final. To read the changes from the betas go to 1.3.0.Beta1 and 1.3.0.Beta2
This contains only changes between 1.3.0.Beta2 and 1.3.0.Final. To read the changes from the betas go to 1.3.0.Beta1 and 1.3.0.Beta2
CollectionMappingStrategy#ADDER_PREFERREDNullValuePropertyMapping strategy not implemented fully (#1685)NullValuePropertyMappingStrategy.SET_TO_DEFAULT (#1699)AdderWrapper / StreamAdderWrapper to use local variable (#1700)unmappedSourcePolicy may lead to false positives (#1648)NullValuePropertyMappingStrategy was not implemented completely (#1685)build() on the @MappingTarget when a Builder is available (#1681)Stream to List and using @AfterMapping on result (#1707)Apply source presence tracking recursively
java.beans.Introspector (#1524)javax.xml.datatype.DatatypeFactory (#1532)isBuilderSetter was added in 1.3.0.Beta1java.util.stream.Stream (#1561)nullValueCheckStrategy on @BeanMapping (#1571)java.time.Instant and java.util.Date (#1595)javax.annotation.processing.Generated if available (#1551)java.sql.Date to a java.time.LocalDate (#1591)null target should NOT be set to null (#1306) - Added new NullValuePropertyMappingStrategy . See PR #1618 and Behavior for more informationIterable element (#1478)AccessorNamingStrategy has been extended with a default init method that allows for initialising it with the Elements and Types utils through the MapStructProcessingEnvironmentMapStructProcessingEnvironment for initialising the BuilderProvider (#1640) - The BuilderProvider has been extended with the same init functionality as the AccessorNamingStrategy@Mapping annotation (#1504)LocalDateTime is used when a simple name is possible (#1576) - With this issue we have also optimised the way we store the required imports (see PR #1642 for more information)java.util.ArrayList not found. MappersImpl cannot be compiled. (#1590)@NotNull (#1558) - Fixes a generic problem for all usages of annotations with ElementType.TYPE_VARAccessorNamingStrategy has been added for FreeBuilder (see https://github.com/mapstruct/mapstruct/commit/104ebf88da8c6145b790905f0c1db66a3cd35a6b for more information)@InheritConfiguration (#1593) - Add tests to show it is working@Repeatable Mappings (#1633) - There is a bug in the javac compiler that does not report the diagnostics on the correct place. See JDK-8042710 and https://github.com/mapstruct/mapstruct/issues/1628 for tracking it on our sideWith #1456 MapStruct now uses nested source presence tracking for nested objects. If the first property has a presence check method then a presence check would be checked recursively. See the issue description for what has changed.
With #1306 MapStruct now has a NullValuePropertyMappingStrategy that can be used to control how null or not present source properties are updated within a target. The possibilities are:
SET_TO_NULL - If the source property is null or not present the target property is set to null. This is also the default, which is the same behaviour from before.SET_TO_DEFAULT - If the source property is null or not present the target property is set to default (empty list, empty set, new object instantiation etc)IGNORE - If the source property is null or not present the target property is not set at allNB: During this we noticed that we handle differently collections / maps for normal mapping methods (i.e. we were setting those to null if the source property was null or not present). This is now changed and collections / maps won't be set if the source property is null or not present. In such case one needs to use @ObjectFactory or set the default in the constructor of the target object
NB2: In 1.2.0.Final with #1273 we added support for using NullValueMappingStrategy#RETURN_DEFAULT to control how collections / maps default values are set. We realized that this was a mistake on our side and now one should use NullValuePropertyMappingStrategy#SET_TO_DEFAULT.
See this for more information as well
The BuilderProvider interface has been changed from 1.3.0.Beta1. Now it has an init method that can be used to get access to the Elements and Types utils and the findBuilderInfo method only gets the TypeMirror
Support for Builders (#782 and #802). Support tested with:
BuilderProviderNoOpBuilderProvider (#1418) - BuilderProvider that allows users to disable the using of Builders in MapStruct. You need to enable it explicitly by creating a org.mapstruct.ap.spi.BuilderProvider file in the META-INF/services directory with org.mapstruct.ap.spi.NoOpBuilderProvider as its content.unmappedSourcePolicy (#610)defaultExpression has been added to @Mapping@BeanMapping(ignoreByDefault = true) one can limit the mapping only to the explicitly defined mappings. This annotation actually applies ignore to all target properties, which means that it can be used in configuration mappings to only map explicit properties in base classes@BeforeMapping and @AfterMapping (#1433) - NB: Lifecycle methods for the type being build are not invoked yet (see #1454)@Mapping arguments should be trimmed (#1353)String and java.util.Currency (#1355)InheritInverseConfiguration (#1367) - aligning @Inherit(Inverse)Configuration with strategy AUTO_INHERIT_*Types when searching for TypeElement(s) instead of getting a new TypeElement each time@Mapping annotation when using invalid @Mapping values (#1383)@Mapping (#1387)constant / defaultValue primitive to String mappings (#1401) - See behavior changes@ObjectFactory not called when on an @Context object (#1398)@AfterMapping throws exception on compile (#1339)@InheritInverseConfiguration (#1367)String to org.joda.time.LocalDate issues compiler error (#1370) - When using date format MapStruct tries to validate it by invoking the Joda formatter. This means that the Joda dependency needs to be on the classpath. If the MapStruct processor is invoked from the processor path, and Joda is not there we can't invoke Joda classes. If this is the case we will now issue a warning saying what the user needs to do (add Joda to the processor path) and consider the format as validjavax.annotation.processing.Filer API (#1414)org.joda.time.LocalDate to java.time.LocalDate generated code has compilation error (#1425) - With this fix we have also improved the builtin templates, so something similar should not happen again@BeanMapping(ignoreByDefault=true) treatment with Immutable target (#1452)byte and short values (#1462)String to enum conversion: Compile error in generated mapper (#1460) - Ensures the FQN will be used for SimpleConversion if required, something like this should not happen againNullPointerException when using unknown source properties with shared configuration (#1180)ZonedDateTime to XmlGregorianCalendar losses time zone information (#1523)unmappedSourcePolicy() (#1333)constant and defaultValue in @Mapping (#1459)@ValueMapping javadoc (PR #1480)@Mapping annotation to @InheritInverseConfiguration (#1531)@since tag to @Mapping#defaultExpression() (#1436)With #1401 MapStruct now tries to check if it is possible to assign a defaultValue and / or a constant directly without doing a conversion. For example for the following mapper:
@Mapper
public interface PersonMapper {
@Mapping(target = "price", constant = "10.5")
@Mapping(target = "age", defaultValue = "10)
Order order(OrderDto source);
}
Before the following was generated:
public class PersonMapperImpl implements PersonMapper {
@Override
public Order order(OrderDto source) {
if (source == null) {
return null;
}
Order order = new Order();
order.setConstant(Double.parseDouble("10.5"));
if (source.getAge() == null) {
order.setAge(Integer.parse("10"));
} else {
order.setAge(source.getAge());
}
return order;
}
}
And now the following is generated:
public class PersonMapperImpl implements PersonMapper {
@Override
public Order order(OrderDto source) {
if (source == null) {
return null;
}
Order order = new Order();
order.setConstant(10.5));
if (source.getAge() == null) {
order.setAge(10);
} else {
order.setAge(source.getAge());
}
return order;
}
}
On top of that MapStruct the possible values are more and you can use anything that the compiler would consider as a valid integer (for example 10_000). The parse functions don't accept such strings as valid.
Don't depend on deprecated Sonatype OSS Parent pom
NullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT was not always applied to Collection(s) (#1273)If you need the release notes from the 1.2.0 Beta and CR have a look at the appropriate tags
Extension of mappingInheritanceStrategy, removing of name based ignore reverse mapping (#1255) - See important notice
mappingInheritanceStrategy, removing of name based ignore reverse mapping (#1255) - See important notice@MappingTarget must not be null (#748)1.2.0.Beta2, where we added inheritance of Reverse Mappings as well, the issue #1255 occurred. Therefore the MappingInheritanceStrategy has been extend:
EXPLICIT - Only inherits if explicitly statedAUTO_INHERIT_FROM_CONFIG - Will automatically inherit only forward configurationAUTO_INHERIT_REVERSE_FROM_CONFIG - Will automatically inherit only reverse configurationAUTO_INHERIT_ALL_FROM_CONFIG - Will automatically inherit both forward and reverse configurationAdditionally mappings that only have target name and ignore are inherited only in forward mappings, no matter of the inheritance strategy.
A mapping like:
@Mapping(target = "field1", ignore = true)
TargetBase map(SourceBase source)
Will only inherit forward mappings. There won't be any name based matching for ignoring in the reverse. If you want to ignore a field with the same name in SourceBase you will need to define a mapping like:
@Mapping(target = "field1", source = "field1`, ignore = true)`
TargetBase map(SourceBase source)
Make sure that only types belonging to java.lang are not imported
java.lang are not imported (#1227)size (#1244) - The fix in PR #1245 should stop any other FreeMarker special treatments of parameters@ObjectFactory method is not well defined (#1131)@ObjectFactory with and without parameters (#1242)public interface MyMapper {
@Mapper
public interface NestedMapper {
}
}
The NestedMapperImpl will be generated in the following java file: MyMapper$NestedMapperImpl.java
Add a switch to turn off auto-mappings
null for not present collections in create methods, there is no behavior change in update methods. E.g.Before:
List<String> list = source.getStrings();
if ( list != null ) {
domain.setStrings( new HashSet<String>( list ) );
}
if ( source.hasStrings() ) {
List<String> list = source.getStrings();
domain.setStrings( new HashSet<String>( list ) );
}
After:
List<String> list = source.getStrings();
if ( list != null ) {
domain.setStrings( new HashSet<String>( list ) );
}
else {
domain.setStrings( null );
}
if ( source.hasStrings() ) {
List<String> list = source.getStrings();
domain.setStrings( new HashSet<String>( list ) );
}
else {
domain.setStrings( null );
}
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
One column per quarter.