You are on page 1of 1

package org.services.free_market.User_services.

mapper;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

public class BaseMapper<Entity, DTO> {

private final Entity entity;


private final DTO dto;

public BaseMapper(Entity entity, DTO dto) {


this.entity = entity;
this.dto = dto;
}

Entity createEntity() throws InstantiationException, IllegalAccessException {


return entity;
}

DTO createDTO() throws InstantiationException, IllegalAccessException {


return dto;
}
public Entity toEntity(DTO dto) throws InstantiationException,
IllegalAccessException {
Entity entity = createEntity();
BeanUtils.copyProperties(dto, entity);
return entity;
}
public DTO toDTO(Entity entity) throws InstantiationException,
IllegalAccessException {
DTO dto = createDTO();
BeanUtils.copyProperties(entity, dto);
return dto;
}
}

You might also like