Java代码生成会跳过类型为“ Class”的属性

时间:2018-07-26 06:35:57

标签: java swagger swagger-codegen

我有一个Serializable Java类,它具有String,List和Class类型的三个属性。生成的Java代码省略了类型为“ Class”的属性。

我使用了Swagger-codegen版本2.2.2和Eclipse maven插件Swagger-codegen-maven-plugin版本:2.2.2

复制步骤

在REST服务中使用的任何Java序列化对象中将类添加为属性

使用Maven插件生成Java客户端代码,以获取庞大的代码源

请帮助我了解为什么在代码生成中会跳过类型为'class'的属性?

原始课程:

@JsonDeserialize(using = MyDeserializer.class)
public class MyData<T> {

    private Class<?> type;
    private String dataName;
    private List<?> data;

Swagger生成的类

******
}
/*
 * 
 * 
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 */


package io.swagger.client.model;

import java.util.Objects;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;

/**
 * MyDataobject
 */
@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaClientCodegen", date = "2018-05-28T16:06:37.047+05:30")
public class MyDataobject {
  @SerializedName("data")
  private List<Object> data = new ArrayList<Object>();

  @SerializedName("dataName")
  private String dataName = null;

  public MyDataobject data(List<Object> data) {
    this.data = data;
    return this;
  }

  public MyDataobject addDataItem(Object dataItem) {
    this.data.add(dataItem);
    return this;
  }

   /**
   * Get data
   * @return data
  **/
  @ApiModelProperty(example = "null", value = "")
  public List<Object> getData() {
    return data;
  }

  public void setData(List<Object> data) {
    this.data = data;
  }

  public MyDataobject dataName(String dataName) {
    this.dataName = dataName;
    return this;
  }

   /**
   * Get dataName
   * @return dataName
  **/
  @ApiModelProperty(example = "null", value = "")
  public String getDataName() {
    return dataName;
  }

  public void setDataName(String dataName) {
    this.dataName = dataName;
  }


  @Override
  public boolean equals(java.lang.Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    MyDataobject myDataobject = (MyDataobject) o;
    return Objects.equals(this.data, myDataobject.data) &&
        Objects.equals(this.dataName, myDataobject.dataName);
  }

  @Override
  public int hashCode() {
    return Objects.hash(data, dataName);
  }


  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class MyDataobject {\n");

    sb.append("    data: ").append(toIndentedString(data)).append("\n");
    sb.append("    dataName: ").append(toIndentedString(dataName)).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(java.lang.Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }

}
<build>
        <plugins>
            <!-- <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> 
                <configuration> <mainClass>MyMainClass</mainClass> 
                </configuration> </plugin> -->
            <plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>${version.swagger.codegen}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>swagger.json</inputSpec>
                            <language>java</language>
                            <configOptions>
                                <sourceFolder>src/main/java</sourceFolder>
                            </configOptions>

                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <!-- the following is only necessary if you are using eclipse and m2e -->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>io.swagger</groupId>
                                        <artifactId>swagger-codegen-maven-plugin</artifactId>
                                        <versionRange>[${version.swagger.codegen},)</versionRange>
                                        <goals>
                                            <goal>generate</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>    

0 个答案:

没有答案