-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support Jackson JsonView (#1162)
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains 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