joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.24k stars 1.66k forks source link

Create enum without value #1502

Closed marialenak closed 1 year ago

marialenak commented 1 year ago

When generating an enum through jsonschema2pojo sometimes it's more useful (for serialization and deserialization purposes) to NOT have values. Now the enums are generated like that:

image image

Ideally, there should be a field to indicate whether we need values to be generated or not. Generated example following:

image

eirnym commented 1 year ago

Value is used to map between Java and JSON.

Why do you want to remove it? If value has been removed, how do you imagining mapping between Java and JSON?

joelittlejohn commented 1 year ago

@marialenak In this case, I assume you would prefer this:

public enum ExampleStatus {
     AStatus, BStatus, CStatus;
}

Is that right?

This is possible, but it doesn't follow the long-standing conventions for Java enum naming. With jsonschema2pojo, we cannot attempt to support every possible preferred way of writing Java source code. Our intention is to create a correct approach that maps between JSON and Java and follows Java conventions. It is not the intention of this library to allow endless configurability to get the exact Java source code that you prefer, as that is too big a task and would create a system that is far harder to extend and maintain. See JAXB for a similar approach - the goal is to provide a correct implementation, not to allow generation of whatever source code style you prefer.

So I'm going to close this one, but thanks for the suggestion and feel free to raise another.

adrien1212 commented 1 year ago

@joelittlejohn thank you for your work I have the same problem and you say

This is possible

I don't find where I can do it. Can you explain which part of the code needs to be changed (e.g. create a custom EnumRule and override some method, etc ...)

unkish commented 1 year ago

@adrien1212 you could create a custom EnumRule and override methods that generate code you don't need, eg: