code: protected ClassMapping writeClassMapping (Class<?> sclass)
          throws IOException
      {
          // create our classmap if necessary
          if (_classmap == null) {
              _classmap = Maps.newHashMap();
          }
  
          // look up the class mapping record
          ClassMapping cmap = _classmap.get(sclass);
  
          // create a class mapping for this class if we've not got one
          if (cmap == null) {
              // see if we just want to use an existing class mapping
              Class<?> collClass = Streamer.getCollectionClass(sclass);
              if (collClass != null && !collClass.equals(sclass)) {
                  cmap = writeClassMapping(collClass);
                  _classmap.put(sclass, cmap);
                  return cmap;
              }
  
              // create a streamer instance and assign a code to this class
              Streamer streamer = Streamer.getStreamer(sclass);
              // we specifically do not inline the getStreamer() call into the ClassMapping
              // constructor because we want to be sure not to call _nextClassCode++ if getStreamer()
              // throws an exception
              if (ObjectInputStream.STREAM_DEBUG) {
                  log.info(hashCode() + ": Creating class mapping", "code", _nextClassCode,
                           "class", sclass.getName());
              }
              cmap = createClassMapping(_nextClassCode++, sclass, streamer);
              _classmap.put(sclass, cmap);
  
              // make sure we didn't blow past our maximum class count
              if (_nextClassCode <= 0) {
                  throw new RuntimeException("Too many unique classes written to ObjectOutputStream");
              }
              writeNewClassMapping(cmap);
  
          } else {
              writeExistingClassMapping(cmap);
          }
          return cmap;
      }
docs: Retrieves or creates the class mapping for the supplied class, writes it out to the stream,
  and returns a reference to it.