OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Micronaut] server model generate for property name snake_case do not deserialize

Open
#17,198 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Use "generatorName": "java-micronaut-server",
"serializationLibrary": "micronaut_serde_jackson",
"modelPropertyNaming": "original"

Description

Have a model:

    Battery:
      type: object
      properties:
        battery_id:
          type: string
        slot_id:
          type: integer
          format: int32
        lock_status:
          type: integer
          format: int32
        battery_capacity:
          type: integer
          format: int32
        battery_abnormal:
          type: integer
          format: int32
        cable_abnormal:
          type: integer
          format: int3
openapi-generator version

openapi: 3.0.1

generated model look
@io.micronaut.serde.annotation.Serdeable
@Generated(value="org.openapitools.codegen.languages.JavaMicronautServerCodegen")
@Introspected
public class Battery {
    public static final String JSON_PROPERTY_BATTERY_ID = "battery_id";
    private String batteryId;

    public static final String JSON_PROPERTY_SLOT_ID = "slot_id";
    private Integer slotId;

    public static final String JSON_PROPERTY_LOCK_STATUS = "lock_status";
    private Integer lockStatus;

    public static final String JSON_PROPERTY_BATTERY_CAPACITY = "battery_capacity";
    private Integer batteryCapacity;

    public static final String JSON_PROPERTY_BATTERY_ABNORMAL = "battery_abnormal";
    private Integer batteryAbnormal;

    public static final String JSON_PROPERTY_CABLE_ABNORMAL = "cable_abnormal";
    private Integer cableAbnormal;

    public Battery() {
    }

    public Battery batteryId(String batteryId) {
        this.batteryId = batteryId;
        return this;
    }

    /**
     * Get batteryId
     * @return batteryId
     **/
    @Nullable
    @Schema(name = "battery_id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    public String getBatteryId() {
        return batteryId;
    }

    public void setBatteryId(String batteryId) {
        this.batteryId = batteryId;
    }

    public Battery slotId(Integer slotId) {
        this.slotId = slotId;
        return this;
    }

    /**
     * Get slotId
     * @return slotId
     **/
    @Nullable
    @Schema(name = "slot_id", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    public Integer getSlotId() {
        return slotId;
    }

    public void setSlotId(Integer slotId) {
        this.slotId = slotId;
    }

    public Battery lockStatus(Integer lockStatus) {
        this.lockStatus = lockStatus;
        return this;
    }

    /**
     * Get lockStatus
     * @return lockStatus
     **/
    @Nullable
    @Schema(name = "lock_status", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    public Integer getLockStatus() {
        return lockStatus;
    }

    public void setLockStatus(Integer lockStatus) {
        this.lockStatus = lockStatus;
    }

    public Battery batteryCapacity(Integer batteryCapacity) {
        this.batteryCapacity = batteryCapacity;
        return this;
    }

    /**
     * Get batteryCapacity
     * @return batteryCapacity
     **/
    @Nullable
    @Schema(name = "battery_capacity", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    public Integer getBatteryCapacity() {
        return batteryCapacity;
    }

    public void setBatteryCapacity(Integer batteryCapacity) {
        this.batteryCapacity = batteryCapacity;
    }

    public Battery batteryAbnormal(Integer batteryAbnormal) {
        this.batteryAbnormal = batteryAbnormal;
        return this;
    }

    /**
     * Get batteryAbnormal
     * @return batteryAbnormal
     **/
    @Nullable
    @Schema(name = "battery_abnormal", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    public Integer getBatteryAbnormal() {
        return batteryAbnormal;
    }

    public void setBatteryAbnormal(Integer batteryAbnormal) {
        this.batteryAbnormal = batteryAbnormal;
    }

    public Battery cableAbnormal(Integer cableAbnormal) {
        this.cableAbnormal = cableAbnormal;
        return this;
    }

    /**
     * Get cableAbnormal
     * @return cableAbnormal
     **/
    @Nullable
    @Schema(name = "cable_abnormal", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    public Integer getCableAbnormal() {
        return cableAbnormal;
    }

    public void setCableAbnormal(Integer cableAbnormal) {
        this.cableAbnormal = cableAbnormal;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Battery battery = (Battery) o;
        return Objects.equals(this.batteryId, battery.batteryId) &&
            Objects.equals(this.slotId, battery.slotId) &&
            Objects.equals(this.lockStatus, battery.lockStatus) &&
            Objects.equals(this.batteryCapacity, battery.batteryCapacity) &&
            Objects.equals(this.batteryAbnormal, battery.batteryAbnormal) &&
            Objects.equals(this.cableAbnormal, battery.cableAbnormal);
    }

    @Override
    public int hashCode() {
        return Objects.hash(batteryId, slotId, lockStatus, batteryCapacity, batteryAbnormal, cableAbnormal);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class Battery {\n");
        sb.append("    batteryId: ").append(toIndentedString(batteryId)).append("\n");
        sb.append("    slotId: ").append(toIndentedString(slotId)).append("\n");
        sb.append("    lockStatus: ").append(toIndentedString(lockStatus)).append("\n");
        sb.append("    batteryCapacity: ").append(toIndentedString(batteryCapacity)).append("\n");
        sb.append("    batteryAbnormal: ").append(toIndentedString(batteryAbnormal)).append("\n");
        sb.append("    cableAbnormal: ").append(toIndentedString(cableAbnormal)).append("\n");
        sb.append("}");
        return sb.toString();
    }

    /**
     * Convert the given object to string with each line indented by 4 spaces
     * (except the first line).
     */
    private String toIndentedString(Object o) {
        if (o == null) {
            return "null";
        }
        return o.toString().replace("\n", "\n    ");
    }

}

Input json

{
 "battery_id": "F30001E622",
"slot_id": "1",
 "lock_status": "1",
 "battery_capacity": "0",
"battery_abnormal": "0",
"cable_abnormal": "0"
}

not de serialize only camel case property batteryId

it is possible add to property add @JsonProperty("battery_id")

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the JavaMicronautServerCodegen model template and the handling of generatorName, serializationLibrary, and modelPropertyNaming. Reproduce the issue with the Battery model and the supplied JSON, then verify that generated models deserialize snake_case properties such as battery_id without requiring additional annotations.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.