Skip to content

Faulty Transformation of Element with Type Boolean + Enum #10849

Open
@keil

Description

@keil

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions