Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objects inside array with name ending with "List" are generated as "SomeNameList" #780

Closed
DevinHolland opened this issue Sep 12, 2017 · 4 comments
Milestone

Comments

@DevinHolland
Copy link

Example schema

{
  "title": "example-list-schema",
  "type": "object",
  "properties": {
    "thingList": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "isStuff": {
            "type": "boolean"
          }
        }
      }
    }
  }
}

Output

This generates two class files: ExampleListSchema.class and ThingList.class
ExampleListSchema contains property thingList which is a List<ThingList>.

Expected

I was expecting two class files: ExampleListSchema.class and Thing.class
ExampleListSchema would contain property thingList which would be a List<Thing>

While it is debatable whether the "somethingList" naming pattern is "good", it is a fairly common practice. I would really appreciate support for it in this project.

The class files will parse everything as expected, so this is just a minor inconvenience where a class named "List" isn't actually a list.

@joelittlejohn
Copy link
Owner

Hi Devin. You can use javaType in this situation. It will allow you to choose the class name you want for Thing.

@DevinHolland
Copy link
Author

Thanks for pointing out that feature (I failed to RTFM). That suites my needs.

As "SomethingList" is fairly common, thoughts on making the name happen automatically? Feel free to close if it's not a feature you think is valuable.

Thanks again!

@joelittlejohn
Copy link
Owner

joelittlejohn commented Sep 13, 2017

You've probably seen this already, but just in case you haven't, another option is calling the array things as this would become List<Thing>.

I'm going to tentatively close this one because we get a lot of issues raised where people don't like the heuristics we use to decide a better item class name, and I don't want to create more of that. If others chime in on this ticket then maybe we can think about adding this.

All the same, thanks for raising this!

@it-amosho
Copy link

it-amosho commented Sep 27, 2018

I have the same problem, but my source is from JSON , not from JSON Schema

Is there any workaround for me to generate List<Thing> for thingList instead of List<ThingList> ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants