Skip to content

1.6.0.Beta1

Pre-release
Pre-release
Compare
Choose a tag to compare
@filiphr filiphr released this 04 Nov 22:28
· 24 commits to main since this release

Features

  • Access to target property name (#2688) - @TargetPropertyName can be used to access the target property name to conditional and mapping methods
  • Support passing annotations to generated code (#1574, #2773, #2895, #2983) - Using @AnnotateWith. If a method is annotated with @Deprecated it is automatically copied into the generated code.
  • Support for globally defining nullValueIterableMappingStrategy and nullValueMapMappingStrategy (#2953) - The different strategies can be configured using mapstruct.nullValueIterableMappingStrategy and mapstruct.nullValueMapMappingStrategy respectively
  • Support qualifiers for SubclassMapping annotated methods (#3119)
  • Support defining custom processor options for custom SPI (#3071) - There is also AdditionalSupportedOptionsProvider that can be used to defined the supported options for a custom SPI. The additional options cannot start with mapstruct.
  • Support for defining Javadoc on the generated mapper (#2987) - Using @Javadoc

Enhancements

  • Support for converting between Enum and Integer (#2963)
  • Support for converting between Locale and String (#3172)
  • Support for implicit conversion between java.time.LocalDate and java.time.LocalDateTime (#3199)
  • Support custom name in Spring annotations (#1427) - Can be done using @AnnotateWith(value = Service.class, elements = @AnnotateWith.Element(strings = "cakeMapperV2"))
  • Support meta annotations for @ValueMapping (#3037)
  • Ambiguous mapping method but there is a more specific mapping (#1216)
  • Do not treat getter as an alternative write accessor when using CollectionMappingStrategy#TARGET_IMMUTABLE (#2952)
  • Improve line location report for invalid qualifier for SubclassMapping (#3202)
  • Support @InheritConfiguration for @SubclassMapping in methods with identical signature (#3125)
  • Do not require subclassExhaustiveStrategy when source is a sealed class and all subtypes are specified (#3054)
  • Add validation of String type for @TargetPropertyName (#2863)
  • Support for all lifecycle methods on type being build with builders (#1454)
    • @BeforeMapping with @TargetType the type being build
    • @AfterMapping with @TargetType the type being build
    • @AfterMapping with @MappingTarget the type being build
  • Redundant null checks for nested properties (#3245)
  • @Default on Java Record's constructor isn't respected (#3231)
  • Add InjectionStrategy.SETTER (#3229)
  • Add BeanMapping#unmappedSourcePolicy (#3309)
  • Improve support for Map attributes for immutables (#3089)
  • Support mapping Iterable to Collection (#3376)

Bugs

  • Breaking change: Mapping from Map to Bean (#3144)
  • Condition with @TargetType on Collection fails to compile (#2901)
  • Annotations are automatically passed in forged methods (#3015)
  • Mapping Composition does not work for @SubclassMapping (#3174)
  • Mapping control disabling conversions does not disable them in 2 step mappings (#3186)
  • @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)
  • Arrays cannot be mapped to collection / iterable using an adder method (#3165)
  • Unmapped source properties error when source is mapped to a nested field of the target object (#2781)
  • NullPointerException when ignoring target '.' (#3238) - There is now a compilation error instead of an error in the processor
  • NullValuePropertyMappingStrategy.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)
  • Compile error when using default and static methods in @MapperConfig (#3296)
  • Generic class with adder method and CollectionMappingStrategy.ADDER_PREFERRED fails (#3310)
  • MapStruct can not map only primitives (#3317)
  • 2-step mapping with generics does not work correctly (#2663)
  • MapStruct no longer handles generic mapping methods (in conjunction with immutables) after upgrading from 1.4.x to version 1.5.x (#3163)
  • Ignored mappings when using @InheritConfiguration (#3361)

Documentation

  • Use GitHub new Issue Form Templates (#3008)
  • Mapping composition is no longer experimental (#3239)
  • Improve Lombok integration documentation (#3374)

Build / Refactoring

  • Try to stabilise some date conversion tests (#2806)
  • Avoid unnecessary unboxing of Boolean (#3003)
  • Update FreeMarker to 2.3.32
  • Refactor method selection and use a context to be able to more easily access information (#3280)
  • Update tarLongFileMode to use POSIX (#3340)
  • Simplified some expressions, redundant expressions removed (#3292)
  • Refactor to use presence check for mapping methods (#3347) - Still only internal and custom presence checks methods are not supported for source parameters (see #2610 for that)
  • Update github actions (#3397)
    • Add Java 21 to test matrix
    • Add Java EA to test matrix
    • Removing java 13 and 18 from test matrict

Breaking Changes

Map to Bean

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 inheritance

All, 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 );
}

Sponsoring

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.

Contributors