简体   繁体   中英

serialize a java object with collection

i wanted to serialize an object with a collection of its own type ,serializing gives no issues but on deserializing the object doesent deserialize its collections ,i have the following object

package com.mars.distribution.model;
import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;
import java.util.LinkedList;`
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name="Intermediary_freeFlow",schema="distribution")
public class IntermediaryFreeFlow  implements Cloneable,Serializable{
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE )
    @Column(name="INTERM_ID")
    private int intermId;

    @OneToMany(cascade=CascadeType.ALL)
    @JoinTable(name="INTERMEDIARY_FREEFLOW_RELATION",schema="distribution")
    private List<IntermediaryFreeFlow> intermediaryCollection=new ArrayList<IntermediaryFreeFlow>();


    public int getIntermId() {
        return intermId;
    }
    public void setIntermId(int intermId) {
        this.intermId = intermId;
    }
    public List<IntermediaryFreeFlow> getIntermediaryCollection() {
        return intermediaryCollection;
    }
    public void setIntermediaryCollection(
            List<IntermediaryFreeFlow> intermediaryCollection) {
        this.intermediaryCollection = intermediaryCollection;
    }
}

*

Can you try replacing List with ArrayList in your code. Reason is ArrayList implements Serializable interface, where as List doesn't probably that could be the cause.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM