MapStruct 1.6.1 bug fix released
It is my pleasure to announce the 1.6.1 bug fix release of MapStruct. This release includes 1 enhancement and 8 bug fixes, including some regressions introduced in 1.6.0.
With this release we support the use of the Java 19 LinkedHashSet
and LinkedHashMap
factory methods.
LinkedHashSet and LinkedHashMap factory method
With this release if your source code is Java 19 or later MapStruct is going to use the new factory methods when creating a Set
or Map
On Java 18 or earlier it looks like
Map<AuctionDto, AuctionDto> map = new LinkedHashMap<AuctionDto, AuctionDto>( Math.max( (int) ( auctions.size() / .75f ) + 1, 16 ) ); Set<TargetFoo> set = new LinkedHashSet<TargetFoo>( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) );
Whereas on Java 19 or later it looks like
Map<AuctionDto, AuctionDto> map = LinkedHashMap.newLinkedHashMap( auctions.size() ); Set<TargetFoo> set = LinkedHashSet.newLinkedHashSet( foos.size() );
Behaviour change
Inverse Inheritance Strategy not working for ignored mappings only with target
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); }
Thanks
Thanks to our entire community for reporting these errors.
In alphabetic order this are all the contributors that contributed to the 1.6.1 release of Mapstruct:
We are also accepting donations through Open Collective or GitHub. We’d like to thank all the supporters that supported us with donations in this period:
- adesso SE
- Bileto
- Cybozu
- Frederik Hahne
- Juyoung Kim
- Lansana
- Lee Anne
- Mariselvam
- PRISMA European Capacity Platform GmbH
- St. Galler Kantonalbank AG
Happy coding with MapStruct 1.6.1!!
Download
You can fetch the new release from Maven Central using the following GAV coordinates:
- Annotation JAR: org.mapstruct:mapstruct:1.6.1
- Annotation processor JAR: org.mapstruct:mapstruct-processor:1.6.1
Alternatively, you can get ZIP and TAR.GZ distribution bundles - containing all the JARs, documentation etc. - from GitHub.
If you run into any trouble or would like to report a bug, feature request or similar, use the following channels to get in touch:
- Get help in our GitHub Discussions or StackOverflow
- Report bugs and feature requests via the issue tracker
- Follow @GetMapStruct on Twitter