joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc

Home Page:http://www.jsonschema2pojo.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to generate jakarta imports in version 0.5.1

carl-don-it opened this issue · comments

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

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

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?

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();