Skip to content
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

Inabily to refer to other POJO #1584

Open
Thomasator opened this issue Jan 17, 2024 · 7 comments
Open

Inabily to refer to other POJO #1584

Thomasator opened this issue Jan 17, 2024 · 7 comments

Comments

@Thomasator
Copy link

Hello,

I am trying to convert jsonschema to pojo via maven plugin.

I've encountered a problem. My generated jsonschema has references to some other module to other json schema. When I try to generate from json schema to POJO, this references are included in the class file and they are not refered to. For example, I have my own type (enum) 'Boolean', this type is generated into POJO in other module, but when I generate my class, this enum is included at the back of the file. I'd like to refer to the Boolean.java in the other module and not include it in the same file. Is it possible? Also, this file needs to be in the same directory for some reason. I've tried
external.json this.json .

Thank u for help
Thomasator

@Thomasator Thomasator changed the title Unabily to refer to other jsonschema Inabily to refer to other jsonschema Jan 17, 2024
@abramsz
Copy link

abramsz commented Jan 17, 2024

"Boolean" is not a valid type, use "boolean" instead."Boolean" will be treated as a customized type, and lead to creating a new java class.

@joelittlejohn
Copy link
Owner

joelittlejohn commented Jan 17, 2024

The answer here probably depends on how you are referencing those other types. If you want to refer to something on the classpath, you can use "existingJavaType" to refer to an existing class, so that nothing new is generated. Does that help?

@Thomasator
Copy link
Author

Thomasator commented Jan 17, 2024

@joelittlejohn
For example in the jsonschema the reference looks like this "person" : { "$ref" : "external_jsongen.json#/definitions/Person" }.

@abramsz
The custum Boolean is needed for my app to work, there are more complex types too.

@Thomasator
Copy link
Author

Thomasator commented Jan 17, 2024

I've tried some solutions manually, and all it needs is to add include of the java classes for Example 'include com.example.external_module.Person'.

@Thomasator Thomasator changed the title Inabily to refer to other jsonschema Inabily to refer to other POJO Jan 17, 2024
@joelittlejohn
Copy link
Owner

Are you able to edit the schema like this:

{ "existingJavaType" : "com.example.external_module.Person" }

?

@Thomasator
Copy link
Author

Thomasator commented Jan 17, 2024

@joelittlejohn
Thanks for the response. It works, that is true, but its not the best solution and it will be a lot of work to rewrite my code to support this.

I also still need to have the external.json in the same directory. Is there a work around that?

@Thomasator
Copy link
Author

@joelittlejohn

I've encountred another problem. The solution u mentioned above works for non basic types (enums ...), but if I have "$ref" : "external.json#/definitions/myString" reference to string or int for example, it does not work, because the basic types aren't generated into java classes. Is there some solution for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants