-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of oneOf support. #1193
Comments
any news on this? I ended up splitting my json schema into multiple files so that all pojos are generated, though in a sort of detached state, and then combined those pojos in the generic map obtained from the main schema, but it is not very nice.
having this schema generates a java class like
and having individual pojos generated from
so it is not too bad, but obviously |
@ThanksForAllTheFish I am able to work on the contribution, but I need some info from the maintainer (cc @joelittlejohn), before I dedicate time. |
This idea sounds crazy good and this is exactly the thing we're missing badly. Please let me know if you need some help with it. Our use-case is to use following stuff as input
And generate enums or value objects from it. At the moment generator just generates empty file for someEnum |
any news? |
1 similar comment
any news? |
@piotrtomiak @joelittlejohn Is there any way to do the oneOf pojo generation with a workaround in the json, without factoring out the oneOf array from separate common properties of the objects? |
Hi @piotrtomiak What do you think about the following idea of implementation of the Make a little bit extended POJO with setters that, in case of For example, for this part of schema: "identification": {
"type": "object",
"oneOf": [ {
"properties": {
"idNumber": { "type": "string" }
}
}, {
"properties": {
"person": { "$ref": "person.json" },
}
}]
} The generated public class Identification {
private String idNumber;
private Person person;
public String getIdNumber() {
return idNumber;
}
public void setIdNumber(String idNumber) {
this.idNumber = idNumber;
this.person = null;
}
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
this.idNumber = null;
}
} |
I've tried to avoid
oneOf
for a long time due to issues with Pojo generation, but with my recent large and complex JSON schema I just couldn't do it. So I have implemented support foroneOf
, which would map to POJOs where possible.I would love to contribute that support to the project, but I want to know whether the idea sounds good for you and the contribution would be not be declined immediately.
There are 5 main scenarios I have handled. Except for scenario 1,
properties
on the schema withoneOf
are ignored.There is single branch in
oneOf
. In this case the branch is treated asextends
.All of branches are objects and there is a common constant string field present. E.g.:
It results in generation of a super class with enum "kind" property and following annotations:
It results in generation of an empty super class with following annotations (deduction is available since Jackson 2.12.0):
This results in a collection class extending
ArrayList
orHashSet
with custom deserializer:value
and custom deserializer is created. E.g:Results in (getter/setter removed from the example):
Where
TypeBase
is created as per pt. 2.The text was updated successfully, but these errors were encountered: