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

how to generate jakarta imports in version 0.5.1 #1610

Closed
carl-don-it opened this issue May 10, 2024 · 3 comments
Closed

how to generate jakarta imports in version 0.5.1 #1610

carl-don-it opened this issue May 10, 2024 · 3 comments

Comments

@carl-don-it
Copy link

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
Copy link
Collaborator

unkish commented May 11, 2024

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:

  • applying some transformation plugin (ie. smht. like rewrite-maven-plugin perhaps) such that it would transform generated *.java files by replacing javax.* to jakarta.*.
  • switching to using forked version of jsonschema2pojo patching it to suite the needs

btw, where can i get the rulefactory reference

Not sure what is meant by that

@carl-don-it
Copy link
Author

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
Copy link
Collaborator

unkish commented May 11, 2024

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.
    /**
    * A fully qualified class name, referring to an class that extends
    * <code>org.jsonschema2pojo.rules.RuleFactory</code> and will be used to
    * create instances of Rules used for code generation.
    *
    * @since 0.4.5
    */
    @Parameter(property = "jsonschema2pojo.customRuleFactory", defaultValue = "org.jsonschema2pojo.rules.RuleFactory")
    private String customRuleFactory = RuleFactory.class.getName();

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

2 participants