Methods starting with "is" are ignored #443
-
Hi there, SchemaGeneratorConfigBuilder configBuilder =
new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON)
.with(new JacksonModule(JacksonOption.INCLUDE_ONLY_JSONPROPERTY_ANNOTATED_METHODS));
configBuilder
.without(Option.NONPUBLIC_NONSTATIC_FIELDS_WITHOUT_GETTERS)
.with(
Option.NONSTATIC_NONVOID_NONGETTER_METHODS,
Option.FIELDS_DERIVED_FROM_ARGUMENTFREE_METHODS);
configBuilder.forMethods()
.withPropertyNameOverrideResolver(method -> Optional
.ofNullable(method.getAnnotationConsideringFieldAndGetter(JsonProperty.class))
.map(JsonProperty::value)
.orElse(null)); The POJO I would like to generate a schema for: class BasicObject {
private final boolean isVisible;
private final boolean isHistoricallyInteresting;
...
@JsonProperty("isVisible")
public boolean isVisible() {
return isVisible;
}
@JsonProperty("historicallyInteresting")
public boolean isHistoricallyInteresting() {
return isHistoricallyInteresting;
}
} Tracing through a debugger a bit, it seems like the which has the name It seems like once something is deemed to be ignored there is no way to make an exception here. Is there any way I can wire in special behavior to get out of this, thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @kevin-yu-0602, your observation is correct. Inside the new JacksonModule(JacksonOption.INCLUDE_ONLY_JSONPROPERTY_ANNOTATED_METHODS) {
@Override
protected boolean shouldIgnoreField(FieldScope field) {
// bypass undesired filtering based on fields; also affects getter methods that Jackson doesn't recognize as such
// e.g., when the field and method name are the same
return false;
}
} Adding this to your given example produces the (I assume to be) expected schema: {
"$schema" : "https://json-schema.org/draft/2019-09/schema",
"type" : "object",
"properties" : {
"historicallyInteresting" : {
"type" : "boolean"
},
"isVisible" : {
"type" : "boolean"
}
}
} You can, of course, choose to re-do parts of what the original Just for background: the |
Beta Was this translation helpful? Give feedback.
Hi @kevin-yu-0602,
your observation is correct. Inside the
JacksonModule
, when checking for a getter method's visibility, the underlying field is being considered too, which falls on your feet here it seems.There is no
JacksonOption
for disabling this, but I made the corresponding methodsprotected
so you may override them, e.g. like this: