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

Allow custom names to be supplied when creating an enum #385

Closed
kerr23 opened this issue Jul 2, 2015 · 6 comments
Closed

Allow custom names to be supplied when creating an enum #385

kerr23 opened this issue Jul 2, 2015 · 6 comments

Comments

@kerr23
Copy link

kerr23 commented Jul 2, 2015

Howdy,

Having a heck of a time figuring out how to use enums as i'd like:

The examples show:
"myEnum" : {
"type" : "string",
"enum" : ["one", "secondOne", "3rd one"]
}

but what I really want is
myEnum = {
ONE (1),
TWO (2),
THREE (3)
}

Thanks

@joelittlejohn
Copy link
Owner

Ah, there's no feature that allows you to specify custom names for your
enums. The tool will simply generate a java-safe name from the given value.
On 2 Jul 2015 20:03, "David Kerr" notifications@github.com wrote:

Howdy,

Having a heck of a time figuring out how to use enums as i'd like:

The examples show:
"myEnum" : {
"type" : "string",
"enum" : ["one", "secondOne", "3rd one"]
}

but what I really want is
myEnum = {
ONE (1),
TWO (2),
THREE (3)
}

Thanks


Reply to this email directly or view it on GitHub
#385.

@kerr23
Copy link
Author

kerr23 commented Jul 2, 2015

Ah thanks! Do you think that a custom type would work in this case?

@joelittlejohn
Copy link
Owner

It's just about possible (custom type, plus custom Jackson serializer) but
would be very complicated solution I think.

I'd suggest just using 1, 2, 3. You'll get underscores added as a prefix to
make a Java-safe name. I guess this may have been an example and not the
actual values you have. Either way, I'd simply allow the plugin to decide a
name and don't get to particular about the code produced. It's never going
to be as perfect as a hand-written API, but you'll get most benefit if you
go with the flow. Hopefully the generated values are at least
human-readable on some level.
On 2 Jul 2015 20:30, "David Kerr" notifications@github.com wrote:

Ah thanks! Do you think that a custom type would work in this case?


Reply to this email directly or view it on GitHub
#385 (comment)
.

@kerr23
Copy link
Author

kerr23 commented Jul 3, 2015

Well, imagine a status flag where in the database it's represented as 1,2,3,4 but in the app it's ACTIVE/PENDING/CANCELLED/REMOVED. That's really all i'm trying to make happen. The custom type + custom jackson serializer seems like it may be too complicated to be good. I'll try to think of something else. Thanks!

@joelittlejohn
Copy link
Owner

I guess ideally you'd like some way of annotating the enum values to dictate the Java names. Since the values sit alone in a plain array, there's no real opportunity to add additional metadata. I guess we could have something alongside the enum values like:

{
  "type" : "integer",
  "enum" : [1, 2, 3, 4],
  "javaEnumNames" : ["ACTIVE", "PENDING", "CANCELLED", "REMOVED"]
}

@kerr23
Copy link
Author

kerr23 commented Jul 6, 2015

Yeah something like that would be awesome. I think then mybatis/jackson would "just work"

@joelittlejohn joelittlejohn changed the title What's the syntax to map a value to an enum? Allow custom names to be supplied when creating an enum Aug 3, 2015
@joelittlejohn joelittlejohn added this to the 0.4.14 milestone Aug 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants