code: private synchronized void writeObject(ObjectOutputStream out) throws IOException {
  
          // todo: for multithreaded usage this block needs to be synchronized
          out.defaultWriteObject();
  
          // spec: only write children if not using a peer
          if (this.equals(getPeer())) {
              writeChildren(out);
          }
          else {
              out.writeInt(0);
          }
  
          // write event handlers
          int serializable = 0;
          for (BeanContextMembershipListener listener : _bcMembershipListeners) {
              if (listener instanceof Serializable) serializable++;
          }
  
          out.writeInt(serializable);
          if (serializable > 0) {
              for (BeanContextMembershipListener listener : _bcMembershipListeners) {
                  if (listener instanceof Serializable) {
                      out.writeObject(listener);
                  }
              }
          }
          // end synchronized block
      }
docs: Serialize all serializable children (unless this BeanContext has a peer).  Any
  children which are not serializable not be present upon deserialization. Also
  serialize any BeanContextMembership listeners which are serializable.
  
  @param out ObjectOutputStream to serialize to.