spec icon indicating copy to clipboard operation
spec copied to clipboard

Java generator always adds @Json annotations for enums

Open micro-jumbo opened this issue 1 year ago • 3 comments

Describe the bug

Java generator always adds @Json annotations for enums

To Reproduce

For document:

{
  "asyncapi": "2.3.0",
  "id": "urn:my:service",
  "defaultContentType": "application/json",
  "info": {
    "title": "My services",
    "version": "1.0.0"
  },
  "channels": {
    "accepted": {
      "subscribe": {
        "message": {
          "name": "SuccessMessage",
          "title": "SuccessMessage",
          "payload": {
            "type": "object",
            "title": "SuccessMessage",
            "properties": {
              "result": {
                "title": "SuccessMessageResult",
                "type": "string",
                "const": "SUCCESS"
              },
              "message": {
                "type": "string",
                "title": "SuccessMessageMessage"
              }
            },
            "required": [
              "result"
            ],
            "additionalProperties": false
          }
        }
      }
    }
  }
}

and generator:

const generator = new JavaGenerator({
  collectionType: "List",
});

generated SuccessMessageMessage enum contains Jackson annotations (@JsonValue and @JsonCreator), but it shouldn't:

import com.fasterxml.jackson.annotation.*;

public enum SuccessMessageResult {
  SUCCESS("SUCCESS");

  private String value;

  SuccessMessageResult(String value) {
    this.value = value;
  }
    
  @JsonValue
  public String getValue() {
    return value;
  }

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

  @JsonCreator
  public static SuccessMessageResult fromValue(String value) {
    for (SuccessMessageResult e : SuccessMessageResult.values()) {
      if (e.value.equals(value)) {
        return e;
      }
    }
    throw new IllegalArgumentException("Unexpected value '" + value + "'");
  }
}

These should be generated only when Jackson annotations are enabled.

micro-jumbo avatar Jul 14 '22 17:07 micro-jumbo

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

github-actions[bot] avatar Jul 14 '22 17:07 github-actions[bot]

Issue moved to asyncapi/modelina #812 via ZenHub

jonaslagoni avatar Jul 14 '22 18:07 jonaslagoni

Can you close down this issue @micro-jumbo, its not related to the spec 🙂

jonaslagoni avatar Jul 14 '22 18:07 jonaslagoni