upgrade jsonschema2pojo from 0.4.23 to 1.0.0 for jdk11 migration

349 views
Skip to first unread message

tabho

unread,
Mar 14, 2019, 8:39:37 PM3/14/19
to jsonschema2pojo-users
Hi All,

I am doing migration to jdk11.

I updated org.jsonschema2pojo:jsonschema2pojo-core: and jsonschema2pojo-cli from 0.4.23 to 1.0.0.

eg:- A multi module gradle  project


    sub project 1 :- build.gradle
    compile 'org.jsonschema2pojo:jsonschema2pojo-core:1.0.0'

    subproject 2: build.gradle

dependencies {
    generatePojos 'org.jsonschema2pojo:jsonschema2pojo-cli:1.0.0'
   (other dependencies)
}

task generatePojos(type: JavaExec) {
    classpath = configurations.generatePojos
    main = 'org.jsonschema2pojo.cli.Jsonschema2PojoCLI'
    args = [
            "--output-encoding", "UTF-8",
            "--source", "schema/",
            "--target", "src/main/java",
            "--package", "",
            "--enable-additional-properties",
            "--remove-old-output",
            "--commons-lang3",
            "--generate-builders",
            "--jsr303-annotations",
            "--joda-dates",
            "--big-decimals",
            "--long-integers"

    ].toList()
}

I ran into Exception in thread "main" org.jsonschema2pojo.exception.GenerationException: javaType does not support generic args (java.util.Map<String,String>), did you mean to use existingJavaType?
        at org.jsonschema2pojo.rules.ObjectRule.createClass(ObjectRule.java:289)

so I changed the schema json file declaring map from javaType to existingJavaType
eg

"profileData": {
      "type": "object",
      "javaType": "java.util.HashMap<String,String>"
    }
  },
  "additionalProperties": false

to

profileData": {
      "type": "object",
      "existingJavaType": "java.util.HashMap<String,String>"
    }
  },
  "additionalProperties": false

So now my pojos are generated. NOW the compileJava task fails as generating pojos have created java.Math package containing BigDecimal.java file and java.time package containing Instant.java, LocalDate.java

error stack trace:-

 src/main/java/java/time/Instant.java:2: error: package exists in another module: java.base

/Users/project/abcd/src/main/java/java/math/BigDecimal.java:2: error: package exists in another module: java.base
package java.math;
^
/Users/project/abcd/src/main/java/java/time/Instant.java:2: error: package exists in another module: java.base
package java.time;
^
/Users/project/abcd/src/main/java/java/time/LocalDate.java:2: error: package exists in another module: java.base
package java.time;
^
/Users/project/abcd/src/main/java/java/math/BigDecimal.java:35: error: incompatible types: java.math.BigDecimal cannot be converted to java.math.BigDecimal
        return this;
.........

If any one can let me know where I am going wrong or missing out some thing, that will be really great.

Thanks in advance.
+Ketan

Joe Littlejohn

unread,
Mar 15, 2019, 3:28:34 AM3/15/19
to jsonschema...@googlegroups.com
Hi Ketan

Anywhere you are referring to an existing Java type, e.g. BigDecimal, Instant, etc you now need to use existingJavaType instead of javaType.


In 1.0.0 we do not automatically try to determine whether you are trying to reuse and existing class or naming a new one, because this was causing other problems. You now need to be specific. If you just want to give a Java name to your new class, you use javaType. To use an existing class you must use existingJavaType.

Hope this helps

Joe


--
You received this message because you are subscribed to the Google Groups "jsonschema2pojo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-...@googlegroups.com.
Visit this group at https://groups.google.com/group/jsonschema2pojo-users.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages