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

Enum not getting generated correctly with CamelCase values #1310

Closed
iuvrayan opened this issue Aug 27, 2021 · 2 comments
Closed

Enum not getting generated correctly with CamelCase values #1310

iuvrayan opened this issue Aug 27, 2021 · 2 comments
Milestone

Comments

@iuvrayan
Copy link

iuvrayan commented Aug 27, 2021

I have given the following enum mapping in json schema

{
   "$schema": "http://json-schema.org/draft-04/schema#",
   "additionalProperties": false,
   
   "properties": {
		"Person": {
			"$ref": "#/definitions/Person"
		}
	}, 
	"type": "object",
	
   "definitions": {
      "Person": {
         "properties": {
            "name": {"type": "string"},
            "age": {"type": "number", "minimum": 18, "maximum": 64},
            "gender": {"$ref": "#/definitions/GenderType"}
         }, 
         "required": ["name", "age", "gender"], 
         "type": "object"
      },
      
      "GenderType": {
         "enum": [
           "Male",
           "Female",
           "FeMale",
           "She_Male",
           "HE_MALE",
           "HUMAN"
         ],
         "javaEnums": [
            {"name": "Male"},
            {"name": "Female"},
            {"name": "FeMale"},
            {"name": "She_Male"},
            {"name": "HE_MALE"},
            {"name": "HUMAN"}
         ],
         "javaType": "com.example.GenderType"
      }
   }
}

and the produced class has the enum structure as the following:

@Generated("jsonschema2pojo")
public enum GenderType {

    Male("Male"),
    Female("Female"),
    FeMale_("FeMale"),
    She_Male("She_Male"),
    HE_MALE("HE_MALE"),
    HUMAN("HUMAN");

I expected the FeMale to match exactly but it got generated as FeMale_

Kindly request you to fix this to obey the name given in the javaEnums for the generated classes.

@joelittlejohn
Copy link
Owner

Yes, I don't know why this is using .equalsIgnoreCase instead of equals:

since Java enums do allow constants to use the same name as long as the case is different. I suspect this was simply not understood at the time.

@joelittlejohn
Copy link
Owner

Fixed by #1329

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