jsonschema-generator icon indicating copy to clipboard operation
jsonschema-generator copied to clipboard

Support for @JsonIdentityReference and @JsonIdentityInfo

Open JanLabrie opened this issue 6 years ago • 2 comments

When a member of a Java class is annotated with @JsonIdentityReference, Jackson will serialize it as a reference to another object, instead of the full nested object. The reference is derived from the @JsonIdentifyInfo annotation on the referenced class.

Examples and Javadoc is found here and here

The current schema generator does not take that into account.

I would be good when the generator will recognize the @JsonIdentifyReference in the Jackson module and generate the type information of the id of the references object instead of the object itself.

In my project I made an implementation of this. I will prepare a PR for it, so you can form an opinion.

JanLabrie avatar Jun 09 '20 19:06 JanLabrie

The idea of it being serialised one way the first time it is encountered vs. subsequent encounters is a bit daunting. But if you use it alwaysAsId = true I guess it should be straightforward.

Looking forward to the PR.

CarstenEnglert avatar Jun 09 '20 22:06 CarstenEnglert

Hi @JanLabrie,

I guess you didn't get around to providing that PR. I'll introduce the basic version myself now in #298.

I'd still appreciate it if you happened to have some feedback on my solution. 😉

CarstenEnglert avatar Oct 30 '22 23:10 CarstenEnglert