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

Handling class name clashes when generating POJOs from examples.

Selaron opened this issue · comments

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.