Inspectopedia Help

'@Serial' annotation can be used

Reports methods and fields in the Serializable and Externalizable classes that are suitable to be annotated with the java.io.Serial annotation. The quick-fix adds the annotation.

Example:

class Main implements Serializable { private static final long serialVersionUID = 7874493593505141603L; private void writeObject(ObjectOutputStream out) throws IOException { } }

After the quick-fix is applied:

class Main implements Serializable { @Serial private static final long serialVersionUID = 7874493593505141603L; @Serial private void writeObject(ObjectOutputStream out) throws IOException { } }

Example:

class Main implements Externalizable { protected Object readResolve() throws ObjectStreamException { return "SomeObject"; } }

After the quick-fix is applied:

class Main implements Externalizable { @Serial protected Object readResolve() throws ObjectStreamException { return "SomeObject"; } }

For more information about all possible cases, refer to the Javadoc of the java.io.Serial class.

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

MissingSerialAnnotation
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Serialization issues

This inspection depends on the Java feature '@Serial annotation', which is available since Java 14.

New in 2020.3

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.2, Qodana for JVM 2024.2,

Can be installed with plugin:

Java, 242.22892

Last modified: 11 September 2024