joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.24k stars 1.66k forks source link

how to generate jakarta imports in version 0.5.1 #1610

Closed carl-don-it closed 6 months ago

carl-don-it commented 6 months ago

my project use version 0.5.1, and we need to upgrade the javax to jakarta, but we use a very complicated rulefactory and i don't want to upgrade the version, do you have any better solution? btw, where can i get the rulefactory reference

unkish commented 6 months ago

Hi

As you're using "complicated rulefactory" (assuming it's a custom rulefactory), one option could be changing it to use custom rules (extend rules that add javax.*) in such way that logic will be overridden to generate jakarta.* instead. Other possibilities could be:


btw, where can i get the rulefactory reference

Not sure what is meant by that

carl-don-it commented 6 months ago

thanks, applying some transformation plugin would be easier,.

i mean is there any document that can guide me to write a rulefactory and explain how it works?

unkish commented 6 months ago

is there any document that can guide me to write a rulefactory and explain how it works?

I don't think that there is any official document. However I've pointed out several times and other people have posted examples on how to do that, see for example given comment.

TLDR:

  1. create a class that extends RuleFactory
  2. override methods that return rule(s) of interest to you to return custom (class extends *Rule) rule(s) which would have logic that suits your needs
  3. make sure that custom rule factory class as well as custom rules and all needed stuff is on class path during jsonschema2pojo execution
  4. point jsonschema2pojo at your custom rulefactory via configuration property eg. https://github.com/joelittlejohn/jsonschema2pojo/blob/fd3407b2117d55a5c7f05440dca2b4424971bd4d/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java#L303-L311