Showing nested properties as first level using custom entity view

Hi,

I would like to ask if its possible to show nested properties as first level fields in a custom list API I have implemented.

For example, I have an entity lets say SystemUser (contains phone) which is one is to one with Cuba User. Now I have implemented an API to list system users but I also want to show email (there in cuba user) as a first level field.

Can I achieve above use case just by creating a customer entity view and passing that to EntitySerializationAPI. Creating a custom DTO and mapping properties 1 by 1 seems overkill.

Let me know if any clarifications needed.

Thanks

Hi,

One of possible solutions is to create a method annotated with @MataProperty annotation in your SystemUser entity:


    @MetaProperty
    public String getEmail() {
        return PersistenceHelper.isLoaded(this, "user") && PersistenceHelper.isLoaded(user, "email")
                ? user.getEmail() : null;
    }

Then, if “email” attribute and a user with loaded email property are included to the view for SystemUser, you’ll get the “email” attribute at first level.