I want to use Foo::toString as source in @org.mapstruct.Mapping
Solutions below doesn't work:
@Mapping(source = "value.toString()", target = "date")
String map(Foo value);
java: The type of parameter "value" has no property named "toString()".
@Mapping(source = "java(value.toString())", target = "date")
String map(Foo value);
java: No property named "java(value.toString())" exists in source parameter(s).
- I cannot change
Fooclass (noLombokinsite) - Mapper configuration:
@Mapper(componentModel = "spring"). - Any advice?
Let's define Foo as:
public class Foo {
private final int x;
public Foo(int x) {
this.x = x;
}
public String toString() {
return "" + this.x;
}
}
using:
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.4.2.Final</version>
</dependency>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>