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

Default value for property of "integer enum" type caused POJO compilation error #706

Closed
s13o opened this issue Mar 19, 2017 · 3 comments
Closed

Comments

@s13o
Copy link
Contributor

s13o commented Mar 19, 2017

POJO like this generated wrong and can't be compiled

 {
    "javaType" : "com.example.enums.IntegerEnumToSerialize",
    "properties" : {
       "testEnum" : { 
          "type" : "integer",
          "enum" : [1, 2, 3],
          "javaEnumNames" : ["One", "Two", "Three"],
          "default": 3
      }
    }
}

It can be reproduced easily with jsonschema2pojo/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/EnumIT.java test

s13o pushed a commit to s13o/jsonschema2pojo that referenced this issue Mar 19, 2017
s13o pushed a commit to s13o/jsonschema2pojo that referenced this issue Mar 20, 2017
@joelittlejohn
Copy link
Owner

joelittlejohn commented Mar 20, 2017

Note, the error here relates to how the default value is passed to the enum fromValue method - it's currently always passed as a string e.g. (from the above schema)

@JsonProperty("testEnum")
private IntegerEnumToSerialize.TestEnum testEnum
   = IntegerEnumToSerialize.TestEnum.fromValue("3");
...
@JsonCreator
public static IntegerEnumToSerialize.TestEnum fromValue(Integer value) {
...

@s13o
Copy link
Contributor Author

s13o commented Mar 21, 2017

I know, fixed already.
Will try to commit soon (again :) )

s13o pushed a commit to s13o/jsonschema2pojo that referenced this issue Mar 21, 2017
s13o pushed a commit to s13o/jsonschema2pojo that referenced this issue Mar 21, 2017
s13o pushed a commit to s13o/jsonschema2pojo that referenced this issue Mar 22, 2017
s13o pushed a commit to s13o/jsonschema2pojo that referenced this issue Mar 22, 2017
@joelittlejohn
Copy link
Owner

joelittlejohn commented Mar 26, 2017

Closed by #706 from @thachhoang. Thanks for raising this and helping to improve the project @s13o!

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