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

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

rushabh0701 opened this issue · comments

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!

commented

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.