我有一个需要转换为“blob”对象并存储到数据库中的序列化对象。以前我们用来存储一个由其他项目对象定义的对象,但是它遵循序列化规则,因为它遇到了很多问题,所以我们决定改变现在只包含原始对象的结构“blob”对象(String,布尔值,整数等)。到目前为止,我们可以使所有的属性期望两个将对象转换为Blob对象的问题
private byte[] encode(ScheduledReport schedSTDReport)
{
byte[] bytes = null;
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(schedSTDReport);
oos.flush();
oos.close();
bos.close();
//byte [] data = bos.toByteArray();
//ByteArrayOutputStream baos = new ByteArrayOutputStream();
//GZIPOutputStream out = new GZIPOutputStream(baos);
//XMLEncoder encoder = new XMLEncoder(out);
//encoder.writeObject(schedSTDReport);
//encoder.close();
bytes = bos.toByteArray();
//GZIPOutputStream out = new GZIPOutputStream(bos);
//out.write(bytes);
//bytes = bos.toByteArray();
}
上述被写入团块 斑点包含
public class ScheduledReport extends ScheduledReportInfo implements Serializable {
private SupervisoryScope _scope = null;
private Report _attributes = null;
private ScheduledReportScheduleBase _schedule = null;
private HashMap selectionList = new HashMap();
private EmailInfo _emailInfo = null;
private String _pdfFileName = null;
private short _baseDateOffset = -1;
在报告对象有follwoing属性
private String deflt = null;
private Object guiValue = null;
protected Object serverValue = null;
可变对象可以有任何形式的阵列列表,字符串,布尔或一个类对象。 但是,一旦解码为实际对象,它就需要将类型转换为任意类型。我们的目标是将此对象转换为原始类型和存储中的任何一种,并将其作为原始值恢复。基本上我们认为每个对象都是以对象类型附加的字符串的形式附加到它上面,如'1_整数','Y_Boolean'并转换为blob,同时恢复拆分字符串并将该字符串用作反射的一部分以获取用于投射的对象类型。但这不是可行或正确的解决方案。有任何想法吗。