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

feat: support Jackson JsonView #1162

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions idea-plugin/src/main/resources/.recommend.easy.api.config
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,47 @@ json.field.parse.after[@com.fasterxml.jackson.annotation.JsonUnwrapped]=groovy:`
}
```

#[Jackson_JsonView]
# Support for Jackson annotation JsonView
json.cache.disable=true
api.param.parse.before=groovy:session.set("is-param",true)
api.param.parse.after=groovy:session.remove("is-param")

# Cache the JsonView information at the method level
api.method.parse.before=groovy:```
def jsonViews = it.annValue("com.fasterxml.jackson.annotation.JsonView")
//logger.info("method jsonViews:"+jsonViews)
if (jsonViews) {
session.set("json-views", jsonViews)
}
```
api.method.parse.after=groovy:```
session.remove("json-views")
```
# Check if a field should be ignored based on the active JsonView
field.ignore=groovy:```
if(session.get("is-param")){
return false
}
if(it.contextType()!="field"){
return false
}
def jsonViews = session.get("json-views")
//logger.info("field jsonViews:"+jsonViews)
if (jsonViews) {
def fieldViews = it.annValue("com.fasterxml.jackson.annotation.JsonView")
if (fieldViews) {
// Return true if none of the field's views are in the active JsonView
return !fieldViews.any{ fieldView-> jsonViews.any{ jsonView-> jsonView.isExtend(fieldView.name) } }
} else {
// If the field has no JsonView annotation, it should be ignored
return true
}
}
return false
```


#[Gson]*
#Support for Gson annotations
[email protected]#value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ internal class RecommendConfigLoaderTest {
"Jackson_JsonPropertyOrder",
"Jackson_JsonIgnoreProperties",
"Jackson_JsonUnwrapped",
"Jackson_JsonView",
"Gson",
"ignore_transient_field",
"converts",
Expand Down
Loading