code: @SuppressWarnings("unchecked")
  	public <T> Object write(final T object, final DataTypeDescriptor<T> descriptor)
  			throws Exception {
  		if (descriptor == null) throw new NullPointerException("descriptor");
  		if (object == null) return null;
  
  		TypeEnum typeEnum = descriptor.getType();
  		switch (typeEnum) {
  			case BOOL:
  			case INT16:
  			case INT32:
  			case INT64:
  			case FLOAT:
  			case DOUBLE:
  			case STRING: return object;
  			case DATETIME: return writeDate((Date) object);
  			case ENUM: return writeEnum((Enum) object);
  			case LIST: return writeList((List) object, (ListDescriptor) descriptor);
  			case SET: return writeSet((Set) object, (SetDescriptor) descriptor);
  			case MAP: return writeMap((Map) object, (MapDescriptor) descriptor);
  			case MESSAGE: return writeMessage((Message) object);
  			case VOID: return null;
  			default: throw new IllegalArgumentException("Unsupported descriptor " + descriptor);
  		}
  	}
docs: Serializing.