Conversation
Member
Author
|
@kliushnichenko here is some |
Member
Author
|
@SentryMan I'm adding your json-view to jooby. |
Provide a consistent way of filtering JSON output. This API allows developers to define exactly which fields of a Java object should be serialized, supporting both simple flat structures and deep nested graphs.
The API is designed to be library-agnostic, allowing the same projection definition to work across different JSON providers without requiring changes to domain models or POJOs.
Flexible Syntax: Supports Dot-notation (address.city) and Avaje/LinkedIn-style grouping (address(city, zip)).
Type-Safety: Full support for Java method references (User::getName) to provide refactor-safe projections.
Hierarchical Validation: Projections are validated against the target class hierarchy at definition time, including support for unwrapping Collections and Maps.
Fluent & Declarative API: A Projected<T> wrapper for programmatic use and a `@Project` annotation for MVC controllers.
- Programmatic (Script API):
```java
get("/user/{id}", ctx -> {
User user = service.find(ctx.path("id").value());
return Projected.wrap(user)
.include("id, name")
.include(User::getAddress, addr -> addr.include("city"));
});
```
- Declarative (MVC API):
```java
@get
@project("id, name, address(city)")
public User getUser(String id) {
return service.find(id);
}
```
The feature consists of three primary components that work together to define, wrap, and apply the filtering logic.
1. Projection<T>
The engine that parses syntax and validates paths against the class hierarchy.
```java
// Manual definition
Projection<User> p = Projection.of(User.class)
.include("id, address(city)");
```
2. Projected<T>
```java
// Script API
get("/user", ctx -> {
return Projected.wrap(user).include(User::getName);
});
```
3. `@Project`
A declarative annotation for MVC controllers.
```java
// MVC API
@get
@project("id, name")
public User getUser() { ... }
```
Contributor
Sweet, glad you like it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Provide a consistent way of filtering JSON output. This API allows developers to define exactly which fields of a Java object should be serialized, supporting both simple flat structures and deep nested graphs.
The API is designed to be library-agnostic, allowing the same projection definition to work across different JSON providers without requiring changes to domain models or POJOs.
Flexible Syntax: Supports Dot-notation (address.city) and Avaje/LinkedIn-style grouping (address(city, zip)).
Type-Safety: Full support for Java method references (User::getName) to provide refactor-safe projections.
Hierarchical Validation: Projections are validated against the target class hierarchy at definition time, including support for unwrapping Collections and Maps.
Fluent & Declarative API: A Projected wrapper for programmatic use and a
@Projectannotation for MVC controllers.The feature consists of three primary components that work together to define, wrap, and apply the filtering logic.
The engine that parses syntax and validates paths against the class hierarchy.
@ProjectA declarative annotation for MVC controllers.