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;
Version 2.2.1
java -jar swagger-codegen-cli-2.2.1.jar generate -i tmp/name.swagger.yaml -l java -o tmp/client/ --additional-properties modelPropertyNaming=original
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.....
Here is the code: https://github.com/swagger-api/swagger-codegen/blob/7a97c3c37554a4a2cd7919e8ef0ff83d192f0bdf/modules/swagger-codegen/src/main/resources/Java/pojo.mustache#L8
Have you run mvn clean package to rebuild the JAR before generating the code again?
@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
Most helpful comment
@joergi77 here is the command I used: