You will need to use explicit aliases in this case, because Querydsl accepts only paths and alias-operations as arguments to QBean.
List<DTOPerson> names = query.from(p)
.where(p.lastname.like("%smith%"))
.orderBy(p.lastname.asc(), p.firstname.asc())
.list(Projections.bean(DTOPerson.class,
p.lastname.trim().as("lastname"),
p.firstname.trim().as("firstname")));
Is there a way to trim (all) string results?
You can create a custom FactoryExpression, e.g. subclass of QBean, to do that.