0

I have some json schema that I try to convert to pojo classes using jsonschema2pojo.
Unfortunately, I get some duplicated classes generated with an additional __1 postfix on the classname.

You can test this at https://www.jsonschema2pojo.org/. Add this example and hit Preview:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "something": {
      "type": "object",
      "properties": {}
    },
    "other": {
      "type": "object",
      "properties": {
        "physical": {
          "$ref": "#/properties/something"
        }
      }
    }
  }
}

I get the classes Something and Something__1. They have the same code (except the class name).
I found other questions, where someone commented that one can change some ObjectRule and RuleFactory, but I don't want to patch the library.

Is there something with my schema or is this a bug?

Rainer Jung
  • 636
  • 7
  • 23

1 Answers1

0

jung,

The below code might be working for you, I am facing the same issue for a week and walked through the lots of docs and references available.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
        "other": {
      "type": "object",
      "properties": {
        "physical": {
          "existingJavaType":"com.example.Something" // package name with class name
        }
      }
    },
    "something": {
      "type": "object"
    }

  }
}

Refer this

Joosep Parts
  • 5,372
  • 2
  • 8
  • 33
ashish raval
  • 55
  • 1
  • 7
  • Looks like a hack to me, and can only be applied if the schema is only used for Java and it's your own schema, but it's a possible solution. – Rainer Jung Feb 09 '22 at 09:42