mapstruct / mapstruct/mapstruct
Can't use `@Mapping#source` for map keys containg the dot character
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 7.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Expected behavior
Using the new map->bean mapping feature it is not possible to use @Mapping#source for keys containing a . character. Instead, the Map type itself seems to be considered as the source type and its methods are proposed as alternatives.
It's still possible to achieve that with expression of course (as in the commented out line in the example), but it's far less elegant as just using the source.
Actual behavior
error: No property named "a.b" exists in source parameter(s). Did you mean "a.bytes"?
@Mapping(target = "value", source = "a.b")
Steps to reproduce the problem
package com.example;
import org.junit.jupiter.api.Test;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
class MapstructExampleTest {
public static record ExampleBean(String value) { }
@Mapper
public interface ExampleMapper {
@Mapping(target = "value", source = "a.b")
//@Mapping(target = "value", expression = "java(source.get(\"a.b\"))")
ExampleBean map(Map<String, String> source);
}
@Test
void shouldMapToBean() {
Map<String, String> source = Map.of("a.b", "test");
var output = Mappers.getMapper(ExampleMapper.class).map(source);
assertThat(output.value()).isEqualTo("test");
}
}
MapStruct Version
1.5.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ExampleMapper and shouldMapToBean reproducer, focusing on how @Mapping#source resolves the dotted key "a.b" for a Map<String, String> source. Run the reproducer with MapStruct 1.5.3 and trace the source-property resolution path. Done means the mapping compiles and the test produces an ExampleBean whose value is "test".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100