jakartaee / jakartaee/jsonb-api
Feature request: @JsonbView
- Dominant language
- Java
- Stars
- 95
- Forks
- 41
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 35
Description
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.
Contributor guide
Research direction
No files, tests, or entry points are named. Start by reviewing the proposed @JsonbView annotation, discriminator values, and toJson overload examples, then identify the existing Json-B API areas that would need to support view-aware serialization and deserialization; done means an agreed design and corresponding API changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100