Skip to content

feat: add support for enums serialized as JSON objects with @JsonFormat - #5291

Open
Mattias-Sehlstedt wants to merge 1 commit into
swagger-api:masterfrom
Mattias-Sehlstedt:json-format-on-enum
Open

feat: add support for enums serialized as JSON objects with @JsonFormat#5291
Mattias-Sehlstedt wants to merge 1 commit into
swagger-api:masterfrom
Mattias-Sehlstedt:json-format-on-enum

Conversation

@Mattias-Sehlstedt

@Mattias-Sehlstedt Mattias-Sehlstedt commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Thank you for contributing to swagger-core!

Please fill out the following information to help us review your PR efficiently.


Description

Adds so that @JsonFormat(shape = JsonFormat.Shape.OBJECT) is supported for enums.

The change means that enum

@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum ObjectShapeEnum {
  FIRST(1, "one"),
  SECOND(2, "two");

  private final int code;

  private final String label;

  ObjectShapeEnum(int code, String label) {
    this.code = code;
    this.label = label;
  }

  public int getCode() {
    return code;
  }

  public String getLabel() {
    return label;
  }
}

is introspected to

"ObjectShapeEnum" : {
  "properties" : {
    "code" : {
      "format" : "int32",
      "type" : "integer"
    },
    "label" : {
      "type" : "string"
    }
  },
  "type" : "object"
}

instead of

"ObjectShapeEnum" : {
  "enum" : [ "FIRST", "SECOND" ],
  "type" : "string"
}

Fixes: #4506 #3691 #5287

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

Screenshots / Additional Context

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

Successfully merging this pull request may close these issues.

Jackson @JsonFormat doesn't support Enum type

1 participant