code: public static <D extends EntityDTO, E extends JPAEntity> D createDtoObject(Class<D> clazz, E entity) {
          D result = null;
  
          try {
              result = clazz.newInstance();
              BeanUtils.copyProperties(result, entity);
  
              // Now set IDs of JPA entity
              result.setCreatedById(entity.getCreatedBy() != null ? entity.getCreatedBy().getId() : null);
              result.setModifiedById(entity.getModifiedBy() != null ? entity.getModifiedBy().getId() : null);
          } catch (Exception ex) {
              throw new WebApplicationException("DTO transformation failed.", Status.INTERNAL_SERVER_ERROR);
          }
          return result;
      }
docs: Creates BaseDto object and copies properties from entity object.
  
  @param   <D>     BaseDto object type.
  @param   <E>     Entity type.
  @param   clazz   BaseDto entity class.
  @param   entity  entity object.
  
  @return  BaseDto object.
  
  @throws  WebApplicationException  The exception with 500 status will be thrown.