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

For objects in definition block use name as classname #464

Open wsalembi opened 8 years ago

wsalembi commented 8 years ago

The following JSON schema (dummy.json) generates 3 classes: BillingAddress, ShippingAddress and Dummy.

{
  "$schema": "http://json-schema.org/draft-04/schema#",

  "definitions": {
    "address": {
      "type": "object",
      "properties": {
        "street_address": { "type": "string" },
        "city":           { "type": "string" },
        "state":          { "type": "string" }
      },
      "required": ["street_address", "city", "state"]
    }
  },

  "type": "object",

  "properties": {
    "billing_address": { "$ref": "#/definitions/address" },
    "shipping_address": { "$ref": "#/definitions/address" }
  }
}

Why not generate a single Address class and reuse it for the two properties? I know it can be achieved by specifying javaType. But a generation option to enforce this rule globally would be really helpful.

dadrus commented 8 years ago

481 describes the same issue. A possible fix is referenced there as well.