Chrimle / openapi-to-java-records-mustache-templates

Generate Java Records from OpenAPI Specifications
https://chrimle.github.io/openapi-to-java-records-mustache-templates/
Apache License 2.0
3 stars 0 forks source link

Serializable `record` classes should not have `serialVersionUID`-field by default #219

Open Chrimle opened 1 week ago

Chrimle commented 1 week ago

Describe the bug As stated here: https://docs.oracle.com/en/java/javase/20/serializable-records/index.html, there is no need to have this field in generated record classes, as stated:

Specifically, there is no need to add a serialVersionUID field, since the serialVersionUID of a record class is 0L unless explicitly declared, and the requirement for matching the serialVersionUID value is waived for record classes. Rarely, for migration compatibility between normal classes and record classes, a serialVersionUID may be declared, see Section 5.6.2 Compatible Changes of the Java Object Serialization Specification for more details.

To Reproduce Set configOptions.serializableModel=true

Expected behavior The field serialVersionUID is not needed, and should thus not be generated.

Additional context & Versions used This is a bit tricky... this version is 0 by default, and is mostly ignored when deserializing. However, it is needed and does matter when migrating to/from classic java classes.