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

Json file has JSONObject called Data, but library is generating a Java class called Datum instead of Data. #1561

Open
rushabh0701 opened this issue Sep 5, 2023 · 1 comment

Comments

@rushabh0701
Copy link

rushabh0701 commented Sep 5, 2023

Hello all,

I have a JSON file which has JSONObject called data, but when generating the Java class it is changing the class name from Data into Datum. Is there reason for doing it this way?

Thanks for the help!

@rushabh0701 rushabh0701 changed the title Json file has JSONObject field called Data, but library is generating a Java class called Datum. Json file has JSONObject called Data, but library is generating a Java class called Datum. Sep 5, 2023
@rushabh0701 rushabh0701 changed the title Json file has JSONObject called Data, but library is generating a Java class called Datum. Json file has JSONObject called Data, but library is generating a Java class called Datum instead of Data. Sep 5, 2023
@unkish
Copy link
Collaborator

unkish commented Sep 7, 2023

Hi

It's done by Inflector when latter attempts to singularize array item name.

Some "issues" that might be related:


I guess given logic was introduced so that class names would be more "fluent" ie. given following schema:
{
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": "string",
          "position": "integer"
        }
      }
    }
  }
}

At present Item (singular) class is being generated as array item and ends up looking:

@JsonProperty("items")
private List<Item> items;

Whereas without Inflector singularizing class name it would have ended up looking:

@JsonProperty("items")
private List<Items> items;

and one would instantiate a single item in code like

Items item = new Items();

which (opiniated/subjective) would look a bit weird.

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

2 participants