3
votes

Are there any libraries that easily allow projections of Java beans?

I have a bean written with getters and setters as per the Javabean convention, and at runtime in different places I want to take a fully-populated bean, and create a new instance with only a subset of its properties populated from the original.

Could something like QueryDSL be used for this? Jackson has views that could be used in the context of JSON serialization, but I was looking for a Java-to-Java solution.

2
Querydsl uses Apache BeanUtils internally, so it makes to try out BeanUtils.Timo Westkämper

2 Answers

0
votes

Dozer is a bean-mapper that will copy properties using reflection. It can be configured to include only a subset of properties if you want.