Skip to content

Possible swagger hub codegen issue with Enums: @JsonValue annotation is missing from toString() #3611

Description

@ralgor14

Description

The @jsonvalue annotation is missing when codegen creates java code (Server->jaxrs) for Enums.
This annotation should be on toString() method.
The following:
"state": {
"type": "string",
"enum": [
"active",
"inactive"
]
}

causes creation of the following Enum code:
public enum StateEnum {
ACTIVE("active"),

INACTIVE("inactive");

private String value;

StateEnum(String value) {
  this.value = value;
}

@Override
 public String toString() {
  return String.valueOf(value);
}

}

Which causes "active" and "inactive" in JSON files to be unrecognized.
In order to correct it the annotation @jsonvalue should be added before toString():
@OverRide
@jsonvalue
public String toString() {
return String.valueOf(value);
}

It was OK in previous versions of swagger hub.
Annotations are used by jackson's fasterXml package.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions