blaze-persistence icon indicating copy to clipboard operation
blaze-persistence copied to clipboard

Support for right conversion of inherited classes for EntityViewManager#convert

Open elodie-28 opened this issue 1 year ago • 0 comments
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.

elodie-28 avatar Aug 29 '24 07:08 elodie-28