Skip to content

NullValueMappingStrategy with Lists #1273

@kevcodez

Description

@kevcodez

Given the following example

public class Dto {

    List<Long> longs = new ArrayList<>();

    public List<Long> getLongs() {
        return longs;
    }

    public void setLongs(List<Long> longs) {
        this.longs = longs;
    }
}
public class Entity {

    List<Long> longs = new ArrayList<>();

    public List<Long> getLongs() {
        return longs;
    }

    public void setLongs(List<Long> longs) {
        this.longs = longs;
    }
}
@Mapper(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public interface EntityMapper {

    Dto asTarget(Entity entity);

}

The generated mapper looks like this:

    public EntityMapperImpl() {
    }

    public Dto asTarget(Entity entity) {
        Dto dto = new Dto();
        if (entity != null) {
            List<Long> list = entity.getLongs();
            if (list != null) {
                dto.setLongs(new ArrayList(list));
            } else {
                dto.setLongs((List)null);
            }
        }

        return dto;
    }
}

Shouldn't the list set to an empty list rather than null? Or do I have a misunderstanding of the null value mapping strategy?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions