Search code examples
javamaven-pluginjsonschema2pojo

Enum not getting generated correctly by jsonschema2pojo-maven-plugin


I have the following field in json schema of a request:

                    "orderType": {
                        "type": "string",
                        "description": "The orderType indicator.",
                        "enum": [
                            "-1",
                            "0"
                        ]
                    },

And I use the jsonschema2pojo-maven-plugin to generated java classes using this json schmea. This correctly generates the java pojo inside which this enum is added correctly which looks something like this :

public enum OrderType{

        _1("-1"),
        _0("0")
...

Now as per the new requirement I new to add a new enum value "1" to this that is a new OrderType and the schema looks simply like this :

                "orderType": {
                    "type": "string",
                    "description": "The orderType indicator.",
                    "enum": [
                        "-1",
                        "0",
                        "1"
                    ]
                },

jsonschema2pojo-maven-plugin doesn't like this for some reason and it generates the following enum which has error :

 public enum orderType {

        _1("-1", "1"),
        _0("0");

Is this an bug in the jsonschema2pojo-maven-plugin or I need to configure something?


Solution

  • Went through the documentation of jsonschema2pojo-maven-plugin :

    https://github.com/joelittlejohn/jsonschema2pojo/wiki/Reference#javaenumnames

    Which fixed the problem as I can give custom enum names.