joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.24k stars 1.66k forks source link

Handling class name clashes when generating POJOs from examples. #1541

Open Selaron opened 1 year ago

Selaron commented 1 year ago

I'd like to suggest another solution for handling conflicting class names when generating POJOs from example JSON files.

Looking at this example BaseData.json:

{
  "office": {
    "contact": {
      "street": "Some Street",
      "houseNumber": "42",
      "town": "Some Town",
      "phoneNumber": "0118 0",
      "email": "office@somebusiness.tld"
    }
  },
  "emergency": {
    "contact": {
      "phoneNumber": "0118 999 881 999 119 7253"
    }
  },
  "press": {
    "contact": {
      "phoneNumber": "0118 1",
      "email": "press@somebusiness.tld"
    }
  }
}

I end up getting classes named BaseData, Emergency, Office, Press, Contact, Contact_1 and Contact_2.

I'd better prefer to have the latter three classes named OfficeContact, EmergencyContact and PressContact.

In order not to break existing projects this should be an option like combineClassNamesOnCollusion (default false)

Implementation might be more lightweight than #125 I guess.