Skip to content

Commit

Permalink
feat: support Jackson JsonView
Browse files Browse the repository at this point in the history
  • Loading branch information
tangcent committed Sep 7, 2024
1 parent 5ae0736 commit 2178d8a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 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,42 @@ json.field.parse.after[@com.fasterxml.jackson.annotation.JsonUnwrapped]=groovy:`
}
```

#[Jackson_JsonView]
#Support for Jackson annotation JsonView
json.cache.disable=true
# 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(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
field.name=@com.google.gson.annotations.SerializedName#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 2178d8a

Please sign in to comment.