Skip to content

Commit

Permalink
feat: support Jackson JsonView (#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangcent authored Oct 24, 2024
1 parent aef5bc6 commit 99dec75
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
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

0 comments on commit 99dec75

Please sign in to comment.