Does jsonschema-generator work with any annotation libraries that auto-generate getters? #322
-
Wondering if it works with Lombok or Immutables or other libraries that auto-generate getters/setters? I couldn't get it to work quite the way I want with Immutables because I have complicated inheritance in the mix. e.g.
I haven't tried Lombok yet. It's a bit of a pain to introduce it into my company so just wanted to know what approach others have been success with first. References to code examples would be awesome! Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @kanesee, Lombok and similar libraries are adding getters to the compiled Java byte code. The The jackson configBuilder.with(new JacksonModule()); The challenge in your case appears to be that you expect the configBuilder.forFields().withTargetTypeOverridesResolver(field -> Optional
.ofNullable(field.getAnnotationConsideringFieldAndGetterIfSupported(JsonSerialize.class))
.map(JsonSerialize::as)
.map(field.getContext()::resolve)
.map(resolvedSubtype -> List.of(resolvedSubtype))
.orElse(null)); |
Beta Was this translation helpful? Give feedback.
Hi @kanesee,
Lombok and similar libraries are adding getters to the compiled Java byte code. The
jsonschema-generator
is looking at that byte code, i.e., those auto-generated getters should be treated like any old hand-crafted ones. At least that was my assumption so far.The jackson
@JsonIgnore
annotation is being respected, if you include thejsonschema-module-jackson
dependency and its corresponding configuration: https://victools.github.io/jsonschema-generator/#jackson-moduleThe challenge in your case appears to be that you expect the
@JsonSerialize
annotation to provide a drop-in replacement.While that is not part of the default behavior, yo…