Swagger-codegen: [JAVA] classes extending from Serializable classes have no servialVersionId [low prio]

Created on 8 Dec 2016  路  12Comments  路  Source: swagger-api/swagger-codegen

Description

Some classes, which are generated by swagger code-gen, are extending some serializable classes:
public class MyClass extends HashMap<String, String>

and if I look at the extended HashMap<String, String>, I can see it should be serializeable.
public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable

In all generated classes is the serialVersionUID, something like the following missing:
private static final long serialVersionUID = -2410670077461289444L;

Swagger-codegen version

Version 2.2.1

Command line used for generation

java -jar swagger-codegen-cli-2.2.1.jar generate -i tmp/name.swagger.yaml -l java -o tmp/client/ --additional-properties modelPropertyNaming=original

Java Question

Most helpful comment

@joergi77 here is the command I used:

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
  -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml \
  -l java -DserializableModel=true\
  -o /var/tmp/java/serializableModel2/

All 12 comments

Did you switch on the serializableModel flag when generating the code?

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

To show all options, please run java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l java

Please pull the latest master, which should have serialVersionUID added to the model class.

(If your company is using Swagger Codegen, please consider adding your company name to this list)

okay, I have used it without the option --additional-properties serializableModel=true
But if I do it with the option, the private static final long serialVersionUID = -2410670077461289444L; is still missing and will be shown in my IDE as a warning.

Have you pull the latest master? The change was made recently.

Allright, checked out the newest version (branch Master) - but still no auto generated serialVersionUID in my code.....

@wing328 , yes, i have done it before...
other question: i have generated my code with it with -additional-properties serializableModel=true but it only added my implements Serializable.
How do you generate it with this behaviour?

@joergi77 here is the command I used:

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
  -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml \
  -l java -DserializableModel=true\
  -o /var/tmp/java/serializableModel2/

ah... okay, i used it wrong...
but if i use now the -DserializableModel=true the -DhideGenerationTimestamp=true is not working anymore..

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
  -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml \
  -l java -DserializableModel=true -DhideGenerationTimestamp=true \
  -o /var/tmp/java/serializableModel2/

do you see where the problem is?

What about just -DserializableModel=true,hideGenerationTimestamp=true?

(If your company is using Swagger Codegen, please consider adding your company name to this list)

thanks a lot, the adding with , worked

No problem

Was this page helpful?
0 / 5 - 0 ratings