2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-04-28 16:49:39 +02:00
An ``++Externalizable++`` class is one which handles its own ``++Serialization++`` and deserialization. During deserialization, the first step in the process is a default instantiation using the class' no-argument constructor. Therefore an ``++Externalizable++`` class without a no-arg constructor cannot be deserialized.
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class Tomato implements Externalizable { // Noncompliant; no no-arg constructor
public Tomato (String color, int weight) { ... }
}
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class Tomato implements Externalizable {
public Tomato() { ... }
public Tomato (String color, int weight) { ... }
}
----
2021-04-28 18:08:03 +02:00
2021-09-20 15:38:42 +02:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Add a no-arg constructor to this class.
2021-09-20 15:38:42 +02:00
endif::env-github,rspecator-view[]