Fabio Ebner
Fabio Ebner

Reputation: 2783

Dozer mapper field don`t exists

I trying to user Dozer in my app, so I have 2 classes:

public MyEntity{
  private String name;
  private Stirng age;
  private String user;
  private Integer day;
}

public class MyVO{
  private String name;
  private String age;
}

So, first I read the Entity from my db(with all fields filled) then I call the dozer to copy the values from VO to Entity

MyEntity entity = myRepo.findById(1);

entity = mapper.map(myVo, MyEntity.class);

but dozzer first sets null to all props in myEntity and then copy the values from myVo,

It`s possible to keep that props (who does not exist in both object) and copy only that fields that exists(or are mapped in my .xml) file

Upvotes: 0

Views: 709

Answers (1)

John Camerin
John Camerin

Reputation: 722

mapper.map(myVo, MyEntity.class);

This call to Dozer tells it to create a new MyEntity instance and then map the values from myVo. This is why some of your fields are null in the resulting entity.

If you want to update an existing instance using Dozer, call Dozer with the instance instead of the class name, i.e.

mapper.map(myVo, entity);

Note, this does not return the entity back to you since it modifies it in place.

Upvotes: 1

Related Questions