/** * Constructor for <code>SerialJavaObject</code> helper class. * <p> * * @param obj the Java <code>Object</code> to be serialized * @throws SerialException if the object is found not to be serializable */ public SerialJavaObject(Object obj) throws SerialException { // if any static fields are found, an exception // should be thrown // get Class. Object instance should always be available Class<?> c = obj.getClass(); // determine if object implements Serializable i/f if (!(obj instanceof java.io.Serializable)) { setWarning(new RowSetWarning("Warning, the object passed to the constructor does not implement Serializable")); } // can only determine public fields (obviously). If // any of these are static, this should invalidate // the action of attempting to persist these fields // in a serialized form fields = c.getFields(); if (hasStaticFields(fields)) { throw new SerialException("Located static fields in " + "object instance. Cannot serialize"); } this.obj = obj; }
elements[i] = new SerialJavaObject(elements[i]);
/** * readObject is called to restore the state of the {@code SerialJavaObject} * from a stream. */ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { ObjectInputStream.GetField fields1 = s.readFields(); @SuppressWarnings("unchecked") Vector<RowSetWarning> tmp = (Vector<RowSetWarning>)fields1.get("chain", null); if (tmp != null) chain = new Vector<>(tmp); obj = fields1.get("obj", null); if (obj != null) { fields = obj.getClass().getFields(); if(hasStaticFields(fields)) throw new IOException("Located static fields in " + "object instance. Cannot serialize"); } else { throw new IOException("Object cannot be null!"); } }
elements[i] = new SerialJavaObject(elements[i]);