Skip to content

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

Closed

Description

@qgiodau

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.

Activity

  1. unkish commented on Jun 23, 2021

    @unkish
    Collaborator

    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"
                  }
                }
              }
            }
          }
        }
      }
    }
    
  2. joelittlejohn commented on Jun 23, 2021

    @joelittlejohn
    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"
  3. qgiodau commented on Jun 23, 2021

    @qgiodau
    Author

    ok, i will use javaName as suggested.

    thank you.

  4. unkish commented on Jun 27, 2021

    @unkish
    Collaborator

    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 ?

  5. eirnym commented on Jun 27, 2021

    @eirnym

    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

  6. changed the title [-]Rename array item java "ta" to "tum"[/-] [+]Item type for array property 'listFta' is incorrectly named ListFtum[/+] on Jun 30, 2021
  7. added this to the 1.1.2 milestone on Jun 30, 2021
  8. joelittlejohn commented on Jun 30, 2021

    @joelittlejohn
    Owner

    Closed by #1276

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions