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

Unable to generate from schema due to "Path not present"

perNyfelt opened this issue · comments

Using the attached schema: falsstprv_schema.json the jsonSchema2Pojo fails with the following error "Path not present: fals"

the gradle build script calls the plugin as follows

plugins {
  id 'java'
  id "org.jsonschema2pojo" version "1.2.1"
}

jsonSchema2Pojo {
   source = files("${sourceSets.main.output.resourcesDir}/falsstprv_schema.json")
   targetDirectory = file("${project.buildDir}/generated/sources/js2p")
   targetPackage = 'sample'
}

I noticed that it is possible to process and generate Java pojos at https://json2csharp.com/code-converters/json-to-pojo so I suspect the problem is due to some bug in the jsonschema2pojo plugin.

Generating java classes from a sample json on https://www.jsonschema2pojo.org/ also works. I attach the sample here.
example_report_sample.json

Hi

As a workaround you could try set refFragmentPathDelimiters to #/ (default being #/.)

jsonSchema2Pojo {
   source = files("${sourceSets.main.output.resourcesDir}/falsstprv_schema.json")
   targetDirectory = file("${project.buildDir}/generated/sources/js2p")
   targetPackage = 'sample'
   refFragmentPathDelimiters = '#/'
}

Thanks, i got further using refFragmentPathDelimiters. Generation completes but cannot compile due to lots of "duplicate class" errors e.g.

error: duplicate class: sample.Deposit
public class Deposit {

Is there a config i can do to address that?

I'm not sure if it has anything to do with jsonSchema2Pojo plugin.
Please check if you have duplicate class definitions on compile classpath.
Alternatively provide a SSCCE that is reproduces given issue.

OK thank you! In the process of creating a SSCCE i found an issue on my side and the problem with duplicate classes was resolved. The working SSCCE can be found here: https://github.com/perNyfelt/jsonSchema-path-not-present.