Content-Length: 328975 | pFad | https://github.com/mapstruct/mapstruct/issues/3144

FC Breaking change: Mapping from Map to Bean · Issue #3144 · mapstruct/mapstruct · GitHub
Skip to content

Breaking change: Mapping from Map to Bean #3144

Closed
@kirbylink

Description

@kirbylink

Expected behavior

When target and source object contains maps (Map<String, ?>) with same name, then the new function "Mapping from Map to Bean" should not be used

Following Object is used with MapStruct 1.4.2.Final:

@Getter
@Builder(setterPrefix = "with")
public class DispatchServiceRequest {
	private final String topic;
	private final String text;
	private final Map<String, Object> attachments;
	private final Date timestamp;
	private final UUID messageId;
	private final DispatcherService dispatcherService;
	private final Delay delay;
}

The corresponding Mapper that worked out of the box with MapStruct 1.4.2.Final:

@Mapper(componentModel = "spring")
public interface DispatchServiceRequestMapper {
	@Mapping(target = "messageId", ignore = true)
	DispatchServiceRequest mapToDispatchServiceRequest(String topic, String text, Map<String, Object> attachments, Date timestamp, DispatcherService dispatcherService, Delay delay);
}

Actual behavior

With version 1.5.x.Final i get the following errors:

Multiple markers at this line
- Can't map property "Object topic" to "String topic". Consider to declare/implement a mapping method: "String map(Object value)".
- Can't map property "Object attachments" to "Map<String,Object> attachments". Consider to declare/implement a mapping method: "Map<String,Object> map(Object value)".
- Can't map property "Object text" to "String text". Consider to declare/implement a mapping method: "String map(Object value)".
- Can't map property "Object timestamp" to "Date timestamp". Consider to declare/implement a mapping method: "Date map(Object value)".
- Can't map property "Object delay" to "Delay delay". Consider to declare/implement a mapping method: "Delay map(Object value)".
- Can't map property "Object dispatcherService" to "Dispatcher.DispatcherService dispatcherService". Consider to declare/implement a mapping method: "Dispatcher.DispatcherService map(Object value)".

It seems, that the new Feature 3.10. Mapping Map to Bean breaks the old behaviour.
When i remove the parameter Map<String, Object> attachments from the mapper method, it will compile.
When i add for each parameter a mapping like

@Mapper(componentModel = "spring")
public interface DispatchServiceRequestMapper {
	@Mapping(target = "messageId", source = "")
	@Mapping(target = "text", source = "text")
	@Mapping(target = "delay", source = "delay")
	@Mapping(target = "topic", source = "topic")
	@Mapping(target = "timestamp", source = "timestamp")
	@Mapping(target = "attachments", source = "attachments")
	@Mapping(target = "dispatcherService", source = "dispatcherService")
	DispatchServiceRequest mapToDispatchServiceRequest(String topic, String text, Map<String, Object> attachments, Date timestamp, DispatcherService dispatcherService, Delay delay);
}

then it also works but in my opinion this is some extra boilerplate which was not necessary before.

Steps to reproduce the problem

code examples: see above

MapStruct Version

MapStruct 1.5.3.Final

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/mapstruct/mapstruct/issues/3144

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy