blaze-persistence
blaze-persistence copied to clipboard
Support for right conversion of inherited classes for EntityViewManager#convert
trafficstars
This issue is related to this discussion #1926
When an entity have a collection of abstract classes as an attribute and is converted to its corresponding view with EntityViewManager#convert, the collection is converted as the entity view of the abstract class instead of their real class.
Here's a short example mapping for better understanding.
The entity classes
@Entity
public class Person {
// other attributes
// getters and setters omitted for brevity
private long id;
private String firstName;
private String lastName;
private List<Vehicle > vehicles;
}
@Entity
public abstract class Vehicle {
// other attributes
// getters and setters omitted for brevity
private long id;
private String model;
}
@Entity
public class Car extends Vehicle {
// other attributes
// getters and setters omitted for brevity
private int seatCapacity;
}
@Entity
public class Bike extends Vehicle {
// other attributes
// getters and setters omitted for brevity
private int cubicCapacity;
}
The views
@EntityView(Person.class)
public interface PersonView {
@Mapping("concat(firstName, ' ', lastName)")
String getFullName();
List<VehicleView> getVehicles();
}
@EntityView(Vehicle.class)
public interface VehicleView {
String getModel();
}
@EntityView(Car.class)
public interface CarView extends VehicleView {
int getSeatCapacity();
}
@EntityView(Bike.class)
public interface BikeView extends VehicleView {
int getCubicCapacity();
}
If I use EntityViewManager#convert on a Person instance to convert it to a PersonView, all vehicles will be converted to VehicleView instead of their respective CarView or BikeView.