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 @JsonView #1067

Open
RobusK opened this issue Jun 26, 2023 · 2 comments
Open

Support for @JsonView #1067

RobusK opened this issue Jun 26, 2023 · 2 comments
Labels
enhancement New feature or request hilla Issues related to Hilla

Comments

@RobusK
Copy link

RobusK commented Jun 26, 2023

Is your feature request related to a problem? Please describe.
Depending on context, I would like to either send the user the entire dto, or just a subset of its attributes. Eg.

Describe the solution you'd like
Example:

class User {
     @JsonView({Views.Basic, Views.Extended, Views.Admin})
     String username;
     @JsonView(Views.Admin);
     String password;
     @JsonViews(Views.Extended)
     Object[] userSettings;
}

class AdminEndpoint{
    // Admin may see password (or some other privileged field)
    @JsonView(Views.Admin)
    User getUser(){
         service.getUser();
    }

}

class UserEndpoint{
    // When querying a single user, also retrieve the userSettings (which may be many)
    @JsonView(Views.Extended)
    User getUser(){
         service.getUser();
    }

    // When retrieving lists, stick to the basics like id, username etc
    @JsonView(Views.Basic)
    List<User> getAllUsers(){
         service.getAllUsers();
    }
}

Describe alternatives you've considered
One could define separate DTOs for each use case. This is rather burdensome, and JsonView is a widely accepted solution in the Spring ecosystem.

@RobusK RobusK added enhancement New feature or request hilla Issues related to Hilla labels Jun 26, 2023
@platosha
Copy link
Contributor

Thanks. Seems to be a good idea, but it's not a priority for us yet. As mentioned, you can achieve a similar outcome by defining DTOs.

@platosha
Copy link
Contributor

Please upvote this issue if you are interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hilla Issues related to Hilla
Projects
None yet
Development

No branches or pull requests

2 participants