Quantcast
Channel: User Federico klez Culloca - Stack Overflow
Viewing all articles
Browse latest Browse all 492

Answer by Federico klez Culloca for MapStruct : Setting value of now while mapping?

$
0
0

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.


Viewing all articles
Browse latest Browse all 492

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>