Skip to content

Title: Bug: Generated Models Extending Map Lack serialVersionUID #12

@mridang

Description

@mridang

Description

The OpenAPI generator templates are producing Java model classes that extend java.util.HashMap but do not include a serialVersionUID.

The java.util.HashMap class implements the java.io.Serializable interface. According to Java's serialization best practices, any class that implements Serializable (including subclasses) should explicitly declare a serialVersionUID field. The absence of this field can cause an InvalidClassException at runtime if there are discrepancies between the class versions used during serialization and deserialization.

Example

The generated class SAMLServiceAny demonstrates this issue.

Problematic Code:

Java

public class SAMLServiceAny extends HashMap<String, Object> {
  // ... class members ...
}

Expected Behavior

The generated class should include the serialVersionUID to ensure proper versioning during serialization.

Suggested Fix:

Java

public class SAMLServiceAny extends HashMap<String, Object> {
  private static final long serialVersionUID = 1L;

  // ... rest of the class members ...
}

Action Required

The generator template responsible for creating model classes that extend Map needs to be modified to add the private static final long serialVersionUID field.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions