我试图使用swagger-codegen生成的代码来使用我的REST服务,这是在我的swagger.json中定义的(由服务器端由springfox 2.9.0提供)

我正在生成api,模型和支持文件 .
但每次我尝试使用GET api时,都会发生错误:

avax.ws.rs.client.ResponseProcessingException: Problem with reading the data, class xxx.xxx.generatedmodels.MyEntity, ContentType: application/json;charset=UTF-8. .... Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "@id" (Class xxx.xxx.generatedmodels.MyEntity), not marked as ignorable

我的猜测是生成的Model类需要类注释 @JsonIdentityInfo(generator = JSOGGenerator.class)just like they are on the server-side model . (也许 @JsonIgnoreProperties(ignoreUnknown = true) ?)
Is that assumption correct?

If yes ,那么有没有办法配置swagger-codegen在每个模型上添加这个注释?

If no ,我该怎么办才能让ApiClient反序列化收到的实体?

我的swagger-codegen配置如下所示:

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>https://example.com/v2/api-docs</inputSpec>
                <language>java</language>
                <generateApis>true</generateApis>
                <generateModels>true</generateModels>
                <generateSupportingFiles>true</generateSupportingFiles>
                <generateModelDocumentation>false</generateModelDocumentation>
                <generateModelTests>false</generateModelTests>
                <modelPackage>xxx.xxx.generatedmodels</modelPackage>
                <apiPackage>xxx.xxx.generatedapi</apiPackage>
                <invokerPackage>xxx.xxx.generatedinvoker</invokerPackage>
                <configOptions>
                    <dateLibrary>java8</dateLibrary>
                    <sourceFolder>src/main/java</sourceFolder>
                    <java8>true</java8>
                </configOptions>
                <library>jersey2</library>
                <output>../generated-client</output>
                <groupId>xxx.xxx</groupId>
                <artifactId>generatedapiclient</artifactId>
                <artifactVersion>1.0.0</artifactVersion>
            </configuration>
        </execution>
    </executions>
</plugin>

响应看起来像这样(严重缩短 . 有许多对象属性也有"@id" . 此示例进一步匹配swagger.json):
{"@id":"1","id":180,"name":"Test entity"}
json是有效的,我已经检查过了

Edit: 这是我彻底减少和去人格化的swagger.json:

{
  "swagger": "2.0",
  "info": {
    "description": "Api Documentation",
    "version": "1.0",
    "title": "Api Documentation",
    "termsOfService": "urn:tos",
    "contact": {

    },
    "license": {
      "name": "Apache 2.0",
      "url": "http://www.apache.org/licenses/LICENSE-2.0"
    }
  },
  "host": "localhost:9080",
  "basePath": "/",
  "tags": [
    {
      "name": "foobar-controller",
      "description": "REST operations available for FooBar"
    }
  ],
  "paths": {
    "/api/fooBars": {
      "get": {
        "tags": [
          "request-car-controller"
        ],
        "summary": "Find a FooBar by id",
        "operationId": "getBeanUsingGET",
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "Authorization",
            "required": true,
            "type": "string"
          },
          {
            "name": "id",
            "in": "query",
            "description": "id",
            "required": true,
            "type": "integer",
            "format": "int64"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/FooBar"
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          }
        },
        "security": [
          {
            "token": [

            ]
          }
        ]
      }
    }
  },

  "securityDefinitions": {
    "Authorization": {
      "type": "apiKey",
      "name": "Authorization",
      "in": "header"
    }
  },

  "definitions": {
    "FooBar": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64"
        },
        "name": {
          "type": "string"
        }
      },
      "title": "FooBar"
    }
  }

服务器端的FooBar类如下所示:

@Entity
@Table(name = "foobar")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonIdentityInfo(generator = JSOGGenerator.class) // this is what generates the `@id` in the json. I need this.
public class FooBar implements Serializable {

    private Long id;
    private String name;

    public FooBar(){

    }

    public FooBar(String name){
        this.name = name;
    }

    // getters, setters
}