Skip to content

Commit 99dec75

Browse files
authored
feat: support Jackson JsonView (#1162)
1 parent aef5bc6 commit 99dec75

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

idea-plugin/src/main/resources/.recommend.easy.api.config

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,47 @@ json.field.parse.after[@com.fasterxml.jackson.annotation.JsonUnwrapped]=groovy:`
133133
}
134134
```
135135

136+
#[Jackson_JsonView]
137+
# Support for Jackson annotation JsonView
138+
json.cache.disable=true
139+
api.param.parse.before=groovy:session.set("is-param",true)
140+
api.param.parse.after=groovy:session.remove("is-param")
141+
142+
# Cache the JsonView information at the method level
143+
api.method.parse.before=groovy:```
144+
def jsonViews = it.annValue("com.fasterxml.jackson.annotation.JsonView")
145+
//logger.info("method jsonViews:"+jsonViews)
146+
if (jsonViews) {
147+
session.set("json-views", jsonViews)
148+
}
149+
```
150+
api.method.parse.after=groovy:```
151+
session.remove("json-views")
152+
```
153+
# Check if a field should be ignored based on the active JsonView
154+
field.ignore=groovy:```
155+
if(session.get("is-param")){
156+
return false
157+
}
158+
if(it.contextType()!="field"){
159+
return false
160+
}
161+
def jsonViews = session.get("json-views")
162+
//logger.info("field jsonViews:"+jsonViews)
163+
if (jsonViews) {
164+
def fieldViews = it.annValue("com.fasterxml.jackson.annotation.JsonView")
165+
if (fieldViews) {
166+
// Return true if none of the field's views are in the active JsonView
167+
return !fieldViews.any{ fieldView-> jsonViews.any{ jsonView-> jsonView.isExtend(fieldView.name) } }
168+
} else {
169+
// If the field has no JsonView annotation, it should be ignored
170+
return true
171+
}
172+
}
173+
return false
174+
```
175+
176+
136177
#[Gson]*
137178
#Support for Gson annotations
138179

idea-plugin/src/test/kotlin/com/itangcent/idea/plugin/settings/helper/RecommendConfigLoaderTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ internal class RecommendConfigLoaderTest {
9191
"Jackson_JsonPropertyOrder",
9292
"Jackson_JsonIgnoreProperties",
9393
"Jackson_JsonUnwrapped",
94+
"Jackson_JsonView",
9495
"Gson",
9596
"ignore_transient_field",
9697
"converts",

0 commit comments

Comments
 (0)