0

I am using jsonschema2pojo-maven-plugin (0.4.19) to generate Java classes from JSON files.

I have 2 JSON files which have same field "xyz" with different attributes. So once I generate the "xyz" class from the 2nd JSON file, it replaces the first "xyz" class.

Is there any way to create 2nd class in a separate package, or is there any other way to avoid this issue?

approxiblue
  • 6,982
  • 16
  • 51
  • 59
Ankur Jalan
  • 1
  • 1
  • 6
  • Try to define different `javaType` attribute to each of schema's. From [this_issue](https://github.com/joelittlejohn/jsonschema2pojo/issues/481) --- Obviously, I can add use the 'javaType' property as follow to force that class to be generated but this also forces me to put java code reference into my schema that it doesn't feel right. – Silence Dec 22 '16 at 14:09

1 Answers1

1

Move each JSON file to a different subfolder in the source package:

${basedir}/src/main/resources/schema/request/request.json
${basedir}/src/main/resources/schema/response/response.json

Then with this configuration:

<configuration>                    
    <sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
    <targetPackage>com.example.types</targetPackage>                   
</configuration>

2 target packages will be generated:

com.example.types.request.*
com.example.types.response.*
approxiblue
  • 6,982
  • 16
  • 51
  • 59
Kaarthy
  • 11
  • 2