Error in classes that implement java.io.Serializable

Asked

Viewed 284 times

0

I have some classes that implement java.io.Serializable, when I compile, all present Warning:

The serializable class Fat_uc_datastatementsql does not declare a Static final serialVersionUID field of type long

What may be occurring? What is this constant he asks for?

2 answers

1

In fact this is just a Warning (an addict). which can even be disabled with @Suppresswarnings("")

import ...
.
.
.
@SuppressWarnings("serial")
public class AplicacaoEntity implements Serializable {  
    private Long id;
    private String descricao;
.
.
.

or by adding the line in the class : private Static final long serialVersionUID = 1L; as the example below:

import ...
.
.
.
public class AplicacaoEntity implements Serializable {  
    private static final long serialVersionUID = 1L;
    private Long id;
    private String descricao;
.
.
.

Important: if you are mounting a JSF project, remember that every bean with scope Session is required to implement serializable;

I hope I’ve helped;

1


In Runtime each serializable class has a version number (serialVersionUID), in the deserialization the object is checked, if the version of the object is not compatible with the version of the object from whom an Invalidexception class occurs, so when you declare a serializeable class it is convenient to declare a serialVersionUID explicitly that it should be Static, final, and long. But if you do not make explicit a default serialVersionUID will be created at runtime, so it does not become mandatory although you should consider doing, so it is only a Warning and not an error, hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.