Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faulty Transformation of Element with Type Boolean + Enum #10849

Open
keil opened this issue Jan 11, 2021 · 0 comments
Open

Faulty Transformation of Element with Type Boolean + Enum #10849

keil opened this issue Jan 11, 2021 · 0 comments

Comments

@keil
Copy link

keil commented Jan 11, 2021

Reopen of ticket #10546 as the provided fix does not solve the issue. The generated Java code still looks as follows:

/**
 * True or False indicator
 */
@JsonAdapter(ModelBoolean.Adapter.class)
public enum ModelBoolean {
  
  TRUE("true"),
  
  FALSE("false");

  private Boolean value;

  ModelBoolean(Boolean value) {
    this.value = value;
  }

  public Boolean getValue() {
    return value;
  }

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

  public static ModelBoolean fromValue(String text) {
    for (ModelBoolean b : ModelBoolean.values()) {
      if (String.valueOf(b.value).equals(text)) {
        return b;
      }
    }
    return null;
  }

  public static class Adapter extends TypeAdapter<ModelBoolean> {
    @Override
    public void write(final JsonWriter jsonWriter, final ModelBoolean enumeration) throws IOException {
      jsonWriter.value(enumeration.getValue());
    }

    @Override
    public ModelBoolean read(final JsonReader jsonReader) throws IOException {
      Boolean value = jsonReader.nextBoolean();
      return ModelBoolean.fromValue(String.valueOf(value));
    }
  }
}

This is not a valid Java code. The constructor requires a value of type Boolean ModelBoolean(Boolean value), but is called with values of type String TRUE("true").

Tested with Swagegr Codegen Version 2.4.18 and version 3.0.24. Both sould include the fix.

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

No branches or pull requests

1 participant