             } else {
                 throw new CodecError("Could not find suitable decoder", CodecError.DECODE, null, oid);
             }
-
         }
 
+        /**
+         * Return the Class given oid is currently mapped to.
+         * @param oid oid for which to find mapped Class
+         * @return Class mapped (or null if none)
+         */
         public function getOutputClass(oid:int):Class {
             return _oidToType[oid];
         }
 
-        public function getEncoder(value:Object):IPGTypeEncoder {
-            // TODO: This logic is wrong; see the SmartyPants IOC for a correct implementation. Also,
-            // this should take the class of the value to encoded, not the instance itself
-            if (value is int) {
-                return _encoders[int];
-            } else if (value is uint) {
-                return _encoders[uint];
+        /**
+         * Return the encoder for the given Class
+         * @param value for which to find encoder
+         * @return registered encoder
+         * @throws org.postgresql.CodecError if no encoder is registered for the given Class
+         */
+        public function getEncoder(clazz:Class):IPGTypeEncoder {
+            if (clazz in _encoders) {
+                return _encoders[clazz];
             } else {
-                return _encoders[Object(value).constructor];
+                throw new CodecError("Could not find suitable encoder", CodecError.ENCODE, null, Oid.UNSPECIFIED, clazz);
             }
         }
 

package org.postgresql.codec {

    import flash.utils.Dictionary;

    import org.postgresql.CodecError;

    public class CodecFactory {

        private var _decoders:Dictionary;

        private var _typeToOid:Dictionary;
        private var _oidToType:Dictionary;

        /**
         * Constructor. No encoders or decoders are registered by default.
         */
        public function CodecFactory() {
            // TODO: handle defaults. On input, any unknown type should be mapped
            // to Oid.UNSPECIFIED and sent as its String representation. On output,
            // if sent as text, we can destringify and present text.
            _decoders = new Dictionary();
            _encoders = new Dictionary();

