Skip to content

Support CollectionMappingStrategy on @BeanMapping and @Mapping #3708

@yelhouti

Description

@yelhouti

Expected behavior

When I retrieve my data from DB, sometime the collection is Immutable. ex: when using @type(type = "json").
When I do a partial request, I expect it to keep working.
ie: Not try to clear the immutableCollection just create a new Empty one and set it.

Actual behavior

        if ( entity.getTypes() != null ) {
            Set<PartnerType> set = dto.getTypes();
            if ( set != null ) {
                entity.getTypes().clear();
                entity.getTypes().addAll( set );
            }
        }
        else {
            Set<PartnerType> set = dto.getTypes();
            if ( set != null ) {
                entity.setTypes( new LinkedHashSet<PartnerType>( set ) );
            }
        }

Steps to reproduce the problem

Have the target contain an ImmutableCollection ex using Set.of()

    @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
    void partialUpdate(@MappingTarget Partner entity, PartnerDTO dto);

Try to map.

MapStruct Version

Mapstruct 1.5.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions