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

Adding symbols, JSON->JAVA? #596

Closed
amitabhuddi opened this issue Jul 19, 2016 · 4 comments
Closed

Adding symbols, JSON->JAVA? #596

amitabhuddi opened this issue Jul 19, 2016 · 4 comments

Comments

@amitabhuddi
Copy link

When I am trying to convert json scheme to java object and I have an enum which are symbols like ":", "<", etc. The problem there is that when these enums are converted to java, they are done as : "EMPTY(":", "\u2265", "<");" and this token EMPTY is generating an error which is correct since the names to these symbols cant be found. Any solutions for this problem? Thanks in advance.

@amitabhuddi
Copy link
Author

PS. I am using Maven plugin to do that.

@joelittlejohn
Copy link
Owner

Could you give me an example?

@amitabhuddi
Copy link
Author

I have something like this in my json scheme:
"operation": {
"type": "string",
"enum": [ ":", "≥", "<" ]

when this is converting to java object i get something like this:
**public enum Operation {

EMPTY(":", "\u2265", "<");
private final String value;
......**

@joelittlejohn
Copy link
Owner

joelittlejohn commented Jul 20, 2016

Ah, I see. There are no characters in your enum that are valid in a Java identifier.

If you can change the schema, you can add some meaningful names to your enum values using javaEnumNames like this:

https://github.com/joelittlejohn/jsonschema2pojo/blob/f23641fb5a492d86f2e8de001299f21353601df8/jsonschema2pojo-integration-tests/src/test/resources/schema/enum/enumWithCustomJavaNames.json

In this case we don't really have anything useful in the schema to use as a Java identifier. There's still a bug though, you should probably have gotten:

EMPTY(":"),
EMPTY_("\u2265"),
EMPTY__("<")

thachhoang added a commit to thachhoang/jsonschema2pojo that referenced this issue Aug 14, 2016
joelittlejohn pushed a commit that referenced this issue Aug 14, 2016
* Fix Javadoc for TypeRule

* Use unique enum constant names

Fix #596.
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