bikash_binay
bikash_binay

Reputation: 219

How to serialize the object containing List of objects?

I have a class with the following fields and i want to persist it to a file.But it is throwing the following exception... java.io.NotSerializableException: **.VehicleDetailsCollection .

public class VehicleDetailsCollectionWrapper implements java.io.Serializable{

private String updatedTime;

private Map<String,VehicleDetailsCollection> vehicleDetailsDTOList;

    ********************
    ********************
   }

Upvotes: 1

Views: 1494

Answers (2)

Rahul
Rahul

Reputation: 45060

Even your VehicleDetailsCollection class should implement the Serializable interface.

Implementing Serializable in VehicleDetailsCollectionWrapper class makes only the wrapper serializable and not the VehicleDetailsCollection class.

Upvotes: 3

Juned Ahsan
Juned Ahsan

Reputation: 68715

You need to make VehicleDetailsCollection class also Serializable.

Read Java serialization specs for more:

http://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html

Upvotes: 2

Related Questions