diff --git a/idea-plugin/src/main/resources/.recommend.easy.api.config b/idea-plugin/src/main/resources/.recommend.easy.api.config index 2b185af2e..e0a32fcb3 100644 --- a/idea-plugin/src/main/resources/.recommend.easy.api.config +++ b/idea-plugin/src/main/resources/.recommend.easy.api.config @@ -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 field.name=@com.google.gson.annotations.SerializedName#value diff --git a/idea-plugin/src/test/kotlin/com/itangcent/idea/plugin/settings/helper/RecommendConfigLoaderTest.kt b/idea-plugin/src/test/kotlin/com/itangcent/idea/plugin/settings/helper/RecommendConfigLoaderTest.kt index 1d8b8c814..54a8f10de 100644 --- a/idea-plugin/src/test/kotlin/com/itangcent/idea/plugin/settings/helper/RecommendConfigLoaderTest.kt +++ b/idea-plugin/src/test/kotlin/com/itangcent/idea/plugin/settings/helper/RecommendConfigLoaderTest.kt @@ -91,6 +91,7 @@ internal class RecommendConfigLoaderTest { "Jackson_JsonPropertyOrder", "Jackson_JsonIgnoreProperties", "Jackson_JsonUnwrapped", + "Jackson_JsonView", "Gson", "ignore_transient_field", "converts",