From 00baff90006361eef2cdf079f0a426371639cd0d Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 20 Dec 2002 23:27:52 +0000 Subject: [PATCH] Handle Object fields by using readObject() and writeObject() to serialize them assuming they'll contain either a primitive type or an instance of Streamable. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2076 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/java/com/threerings/io/FieldMarshaller.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/java/com/threerings/io/FieldMarshaller.java b/src/java/com/threerings/io/FieldMarshaller.java index 19782b43e..ea5a9f6b1 100644 --- a/src/java/com/threerings/io/FieldMarshaller.java +++ b/src/java/com/threerings/io/FieldMarshaller.java @@ -1,5 +1,5 @@ // -// $Id: FieldMarshaller.java,v 1.2 2002/10/27 18:49:51 mdb Exp $ +// $Id: FieldMarshaller.java,v 1.3 2002/12/20 23:27:52 mdb Exp $ package com.threerings.io; @@ -105,8 +105,8 @@ public abstract class FieldMarshaller // create our table _marshallers = new HashMap(); - // create a marshaller for streamable instances - _marshallers.put(Streamable.class, new FieldMarshaller() { + // create a generic marshaller for streamable instances + FieldMarshaller gmarsh = new FieldMarshaller() { public void readField ( Field field, Object target, ObjectInputStream in) throws Exception { @@ -117,7 +117,15 @@ public abstract class FieldMarshaller throws Exception { out.writeObject(field.get(source)); } - }); + }; + _marshallers.put(Streamable.class, gmarsh); + + // use the same generic marshaller for fields declared to by type + // Object with the expectation that they will contain only + // primitive types or Streamables; the runtime will fail + // informatively if the user attempts to store non-Streamable + // objects in that field + _marshallers.put(Object.class, gmarsh); // create marshallers for the primitive types _marshallers.put(Boolean.TYPE, new FieldMarshaller() {