Skip to content

Item type for array property 'listFta' is incorrectly named ListFtum #1275

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

Closed
qgiodau opened this issue Jun 22, 2021 · 6 comments
Closed

Item type for array property 'listFta' is incorrectly named ListFtum #1275

qgiodau opened this issue Jun 22, 2021 · 6 comments
Milestone

Comments

@qgiodau
Copy link

qgiodau commented Jun 22, 2021

Hi, when i use the following schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  
  "properties": {
   "foo": {
      "type": "object",      
      "properties": {
        "listFta": {
          "type": "array",
          "items": {
		    "properties": {
              "idScheda": {
                "type": "string",
                "description": "IdScheda"
              }
            }
          }
        }        
      }
    }
  }
}

The Foo java class generated, has got a property listFtum instead of listFta:

@JsonProperty("listFta") @Valid private List<ListFtum> listFta = null;

I use the maven plugin for the code generation , but also from website https://www.jsonschema2pojo.org/ , the result is the same.

Can you help me?

Best regards.
Thank you.

@unkish
Copy link
Collaborator

unkish commented Jun 23, 2021

Hi

It looks like duplicate of #148.
As a workaround You could use the javaType extension property to override the class name chosen by the inflector as suggested here: #148 (comment)
Example:

  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "foo": {
      "type": "object",
      "properties": {
        "listFta": {
          "type": "array",
          "items": {
            "javaType": "ListFta",
            "properties": {
              "idScheda": {
                "type": "string",
                "description": "IdScheda"
              }
            }
          }
        }
      }
    }
  }
}

@joelittlejohn
Copy link
Owner

Yes, so the issue here is that when we see an array like 'Products' we make this singular for the item class name, like 'Product'. For words that end in 'ta' (like data) the singular noun ends in 'tum' (like datum). So the inflector class (the class responsible for producing these singular nouns) is a little over-zealous.

I don't really like #148 because it encourages a very specific configuration. It would probably be better to add a config option to disable the inflector. As unkish has said though, for now you should be able to work around this using javaType or javaName inside the items schema.

In the past it has still been useful to add and fix rules in the inflector when we find problems. In this case, it should have a more specific rule I think. The code currently has:

            .singular("([ti])a$", "$1um")

which produces these two rules:

  • "ia" => "ium"
  • "ta" => "tum"

but we should split this like:

            .singular("ia$", "ium")
            .singular("ata$", "atum")

so that we get these two rules instead:

  • "ia" => "ium"
  • "ata" => "atum"

@qgiodau
Copy link
Author

qgiodau commented Jun 23, 2021

ok, i will use javaName as suggested.

thank you.

@unkish
Copy link
Collaborator

unkish commented Jun 27, 2021

I don't really like #148 because it encourages a very specific configuration

@joelittlejohn would it be possible to elaborate a bit on what is meant by very specific configuration ?

@eirnym
Copy link

eirnym commented Jun 27, 2021

The best implementation I'd see here is make this endings modifications being possible to override by a jsonschema2pojo plugin like for types. In this case everyone can modify default behavior as it suits best to a project

@joelittlejohn joelittlejohn changed the title Rename array item java "ta" to "tum" Item type for array property 'listFta' is incorrectly named ListFtum Jun 30, 2021
@joelittlejohn joelittlejohn added this to the 1.1.2 milestone Jun 30, 2021
@joelittlejohn
Copy link
Owner

Closed by #1276

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

4 participants