You can use defaultExpression
in your mapping. It expects a string as an argument, with the following format:
"java(expression)"
Where expression
is the expression you're looking for, so in your case
@Mapping(source = "created", target = "created", defaultExpression = "java(java.time.Instant.now())")
Notice that I used the fully qualified name for the Instant
class, since defaultExpression
can't know where Instant
is (or at least it can't assume you want the one from the standard library), so it can't import it in the file it generates.