Példa


public static final class SomeType {}

public class SerializableField implements Serializable {
public SerializableField( String str ) {
super();
this .str = str;
nonser = new SomeType();
}

private String str;
private SomeType nonser;

private static final long serialVersionUID = 123;
}


Megoldás
Tegye a mezőtípust sorosíthatóvá.

public static final class SomeType implements Serializable {}

public class SerializableField() implements Serializable {

public SerializableField( String str ) {
super();
this .str = str;
nonser = new SomeType();
}

private String str;
private SomeType nonser;

private static final long serialVersionUID = 123;
}

Megoldás
Deklarálja a mezőt átmenetiként.

public static final class SomeType {}

public class SerializableField implements Serializable {

public SerializableField( String str ) {
super();
this .str = str;
nonser = new SomeType();
}

private String str;
private transient SomeType nonser;

private static final long serialVersionUID = 123;


}