Swagger-codegen: how to say swagger-codegen to implement serializable for model classes.

Created on 14 Feb 2017  路  5Comments  路  Source: swagger-api/swagger-codegen

Description

I want the Swagger generated classes to implement Serializable. Is there way i can say to swagger-codegen to implement this ??

Swagger-codegen version

swagger-codegen version : 2.2.1

Swagger declaration file content or url
```yaml

paths:
/pet:
get:
description: pet
tags:
- pet
responses:
'200':
description: got response ok
schema:
$ref: '#/definitions/PetTO'
definitions:
PetTO:
type: object
properties:
id:
type: string
description: pet id
petName:
type: string
description: pet name
```
(for YAML code) or
-->

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i pet.yml -l java --library=okhttp-gson
-o generated_source_code
-c package_config.json

=> With the above Yaml, Swagger-codegen will generate a PetTO class. I want the PetTO class to implement serializable. Is there a way i can say to swagger-codegen to implement serializable for this class.

Java Question

Most helpful comment

Have you tried the following option?

    serializableModel
        boolean - toggle "implements Serializable" for generated models (Default: false)

Ref: java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l java

All 5 comments

Have you tried the following option?

    serializableModel
        boolean - toggle "implements Serializable" for generated models (Default: false)

Ref: java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l java

thanks. it is working with "serializableModel" : true

Hi, where to add this serializableModel" : true
please help

Hi, where to add this serializableModel" : true
please help

add it in the config.json, which you provide as input to the swagger-codegen.

For example, this how my config.json file looks like
{
"invokerPackage" : "com.xxxx.yyyy.zzzz",
"apiPackage" : "com.xxxx.yyyy.zzzz.api",
"modelPackage" : "com.xxxx.yyyy.zzzz.model",
"serializableModel" : true
}

Is it possible to implement Serializable just for a set of classes instead of all?

Was this page helpful?
0 / 5 - 0 ratings