I'm trying to make a JMapper convertion from a class Source to Destination, in the source I have a Date and in the destination a LocalDateTime.
Reading the docs of JMapper the logical way is to make a convertion. However the covertion based on the solution from this question doesn't work and I always get null on the destination date.
Now my code
// Source Entity
@Entity
@Table(name = "source")
public class Source {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column
private Long id;
@Column
private String name;
@Column
private Date date;
// ommited getters and setters
}
// Destination entity
public class Destination {
private Long id;
private String name;
private LocalDateTime date;
// ommited getters and setters
}
// Mapping with API
jMapperAPI = new JMapperAPI();
Conversion dateToLocalDateTime = conversion("dateToLocalDateTime")
.from("date").to("date").type(JMapConversion.Type.STATIC)
.body("return java.time.LocalDateTime.ofInstant(${source}.toInstant(), java.time.ZoneId.systemDefault())");
jMapperAPI.add(mappedClass(Destination.class).add(global()
.excludedAttributes("date"))
.add(dateToLocalDateTime));
// Converting
mapper = new JMapper<>(Destination.class, Source.class, jMapperAPI);
mapper.getDestination(source);