@Test public void testCustomConverter() { Converter<UserDto, User> converter = new Converter<>( userDto -> new User(userDto.getFirstName(), userDto.getLastName(), userDto.isActive(), String.valueOf(new Random().nextInt())), user -> new UserDto(user.getFirstName(), user.getLastName(), user.isActive(), user.getFirstName().toLowerCase() + user.getLastName().toLowerCase() + "@whatever.com")); User u1 = new User("John", "Doe", false, "12324"); UserDto userDto = converter.convertFromEntity(u1); assertEquals(userDto.getEmail(), "johndoe@whatever.com"); }
public final T convertFromEntity(final U entity) { return fromEntity.apply(entity); }
Converter { public final T convertFromEntity(final U entity) { return fromEntity.apply(entity); } }
Converter { public final T convertFromEntity(final U entity) { return fromEntity.apply(entity); } Converter(final Function<T, U> fromDto, final Function<U, T> fromEntity); }
Converter { public final T convertFromEntity(final U entity) { return fromEntity.apply(entity); } Converter(final Function<T, U> fromDto, final Function<U, T> fromEntity); final U convertFromDto(final T dto); final T convertFromEntity(final U entity); final List<U> createFromDtos(final Collection<T> dtos); final List<T> createFromEntities(final Collection<U> entities); }
Converter { public final T convertFromEntity(final U entity) { return fromEntity.apply(entity); } Converter(final Function<T, U> fromDto, final Function<U, T> fromEntity); final U convertFromDto(final T dto); final T convertFromEntity(final U entity); final List<U> createFromDtos(final Collection<T> dtos); final List<T> createFromEntities(final Collection<U> entities);  }