Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for right conversion of inherited classes for EntityViewManager#convert #1932

Open
elodie-28 opened this issue Aug 29, 2024 · 0 comments
Labels

Comments

@elodie-28
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants