class UserConverter implements ToServerConverter<ClientUser, User, ToServerConversionOptions>, ToClientConverter<User, ClientUser, ToClientConversionOptions> {

    @Override
    public User toServer(ClientUser clientObject, User user, ToServerConversionOptions options) throws IllegalParameterValueException, MandatoryParameterNotFoundException {
        if (clientObject.getTenantId() != null) user.setTenantId(clientObject.getTenantId());
        if (clientObject.getUsername() != null) user.setUsername(clientObject.getUsername());
        if (clientObject.getEmailAddress() != null) user.setEmailAddress(clientObject.getEmailAddress());
        if (clientObject.getFullName() != null) user.setFullName(clientObject.getFullName());
        if (clientObject.isEnabled() != null) user.setEnabled(clientObject.isEnabled());
        if (clientObject.isExternallyDefined() != null) user.setExternallyDefined(clientObject.isExternallyDefined());
        if (clientObject.getPassword() != null) {
            if (user.getPassword()!= null && !clientObject.getPassword().equals(user.getPassword())){
                user.setPreviousPasswordChangeTime(new Date());
            }

            String pwd = tryDecryptPwdFromJCryption(clientObject.getPassword());
            user.setPassword(pwd);
        }
        if (clientObject.getRoleSet() != null) {
            Set<Role> newRoles = new HashSet<Role>();
            for (ClientRole role: clientObject.getRoleSet()){
                newRoles.add(roleConverter.toServer(role, null));
            }
            user.setRoles(newRoles);
        }

        return user;
    }

}