I have the following serializable class (implements serializable):
public class Test implements Serializable{
private String id;
private Map<String,Object> otherProperties;
}
However , it seems like this property is causing some problems with serialization :
How can I solve this problem ?
Also , is there any downside in not making this transient or serializable ? Will I be able to serialize this class fully ?
Advertisement
Answer
The Map interface does not extend the Serializable interface, which is why Sonar is warning you.
When serializing an instance of Test, you must choose whether or not you want otherProperties to be serialized.
If you don’t want to serialize otherProperties, then the field should be marked as transient:
private transient Map<String, Object> otherProperties;
Otherwise, you can change the type of otherProperties to an implementation of Map that implements Serializable, such as HashMap.
