I have two set object Set<Foo> fooSet
and Set<Bar> barSet
. Foo
is the entity object and Bar
is the DTO which i want to use for sending data to the UI. I want to copy all the properties from fooSet
into barSet
.
public class Foo {
@Id
@Column(name = "Category_Id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long categoryId;
@OneToMany(mappedBy="productCategory")
private Set<ProductEntity> products;
}
public class BarDto {
private Long categoryId;
private Set<ProductDto> products;
}
I am trying to convert Entity into DTO object like:
public BarDto mapDomainToDto(Foo domain) {
BarDto barDto= new BarDto();
barDto.setCategoryId(domain.getCategoryId());
//trying to do something like:
barDto.setProducts(domain.getProducts());
}
Is there any way to achieve this in Java 8?