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 custom entity view class implementations #1078

Closed
beikov opened this issue May 12, 2020 · 0 comments · Fixed by #1097
Closed

Support custom entity view class implementations #1078

beikov opened this issue May 12, 2020 · 0 comments · Fixed by #1097

Comments

@beikov
Copy link
Member

beikov commented May 12, 2020

The idea is to allow a user to define a concrete class as entity view like this

@EntityView(MyEntity.class)
public class MyView {
  private final Long id;
  private final String name;
  
  public MyView(@IdMapping("id") Long id, @Mapping("name") String name) {
    this.id = id;
    this.name = name;
  }

  // Getter + Setter + equals/hashCode
}

We will need to cleanup some of our expectations that an entity view can be cast to EntityViewProxy. We should also think about allowing @IdMapping on a parameter or maybe include an attribute id in the @EntityView annotation as we need that to be able to support collections.
It would be great if we can somehow treat the parameters like method attributes to support filters and sorting. An important thing here is that we should order attributes according to their attribute index.
The grand goal is to support Java 14 records, but being able to use Lombok data classes should also be possible IMO. Maybe it's enough to introduce a new annotation reader for such classes? A RecordAnnotationReader would build the ViewMapping based on the the record components. A DataClassAnnotationReader would read the bytecode of the constructor and infer the matching fields/methods for the parameters.

I'm scheduling this for 1.5.0 now but I might defer it to 1.6.0 if this is very hard.

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

Successfully merging a pull request may close this issue.

1 participant