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

Feature request: @JsonbView #343

Open
nimo23 opened this issue Sep 8, 2023 · 0 comments
Open

Feature request: @JsonbView #343

nimo23 opened this issue Sep 8, 2023 · 0 comments

Comments

@nimo23
Copy link

nimo23 commented Sep 8, 2023

It would be great to have something like jacksons @JsonView in Json-B, maybe it can be called @JsonbView. It should work like the following example:

// enums to discriminate between different json views
public enum UserSubset{
    MY_SUBSET_1, 
    MY_SUBSET_2;
}

// the user class
public class User {

    private int id;

    @JsonbView("mysubset1")
    private String name;

    // UserSubset.MY_SUBSET_1 => UserSubset.MY_SUBSET_1.name() = "mysubset1"
    @JsonbView(UserSubset.MY_SUBSET_1)
    private Task task;
}

// the task class
public class Task {

    private int id;

    // property will be (de)serialized in mysubset1, mysubset2 and the default one
    @JsonbView("mysubset1, mysubset2")
    private String description;
}

The value of @JsonbView is a common (array of) String or Enum which is used as a discriminator. Using something like

jsonb.toJson(user, "mysubset");
or
jsonb.toJson(user, UserSubset.MY_SUBSET_1);

will outut the json with only the properties annotated with @JsonbView("mysubset1") or @JsonbView(UserSubset.MY_SUBSET_1)

Is something like this already planned?

I think it would be an extremely useful and simple approach to declare various JSON subviews quickly, easily and cleanly.

@nimo23 nimo23 changed the title Feature request: @JsonbSubset Feature request: @JsonbView Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant