gpt4 book ai didi

java - 使用集合序列化 java 对象

转载 作者:行者123 更新时间:2023-12-01 13:45:59 24 4
gpt4 key购买 nike

我想用它自己类型的集合序列化一个对象,序列化没有任何问题,但在反序列化该对象时不会反序列化其集合,我有以下对象

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;
}
}

*

最佳答案

您可以尝试在代码中用 ArrayList 替换 List 吗?原因是 ArrayList 实现了 Serialized 接口(interface),而 List 可能不是原因。

关于java - 使用集合序列化 java 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20376196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com