Write ObjectInstanceWrapper to the response
14328
public static void writeObjectInstanceOutput(final RESTResponse response, final ObjectInstanceWrapper value, final JSONConverter converter) {
        response.setContentType(APIConstants.MEDIA_TYPE_APPLICATION_JSON);

        OutputStream outStream = null;
        try {
            outStream = response.getOutputStream();

            //Converter the value
            converter.writeObjectInstance(outStream, value);

            //Return converter
            JSONConverter.returnConverter(converter);

            outStream.flush();
        } catch (Exception e) {
            throw ErrorHelper.createRESTHandlerJsonException(e, converter, APIConstants.STATUS_INTERNAL_SERVER_ERROR);
        } finally {
            FileUtils.tryToClose(outStream);
        }
    }
86998
private SerializerWrapper getSerializerWrapper(Class cls) {
    SerializerWrapper w = serializers.get(cls);
    if (w != null) {
      return w;
    } else {
      // Try with interfaces implemented
      for (Class c : cls.getInterfaces()) {
        w = serializers.get(c);
        if (w != null) {
          return w;
        }
      }
    }
    return null;
  }
1190765
public void writeObject(java.io.DataOutputStream dataOutputStream)
                    throws ObjectManagerException
    {
        final String methodName = "writeObject";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        methodName,
                        new Object[] { dataOutputStream });

        try {
            dataOutputStream.writeByte(simpleSerialVersion);
            super.writeObject(dataOutputStream);

            if (head == null) {
                dataOutputStream.writeByte(0);
            } else {
                dataOutputStream.writeByte(1);
                head.writeObject(dataOutputStream); // The first element in the list.
                tail.writeObject(dataOutputStream); // The final element in the list.
            } // if (head == null).
            dataOutputStream.writeLong(size);
        } catch (java.io.IOException exception) {
            // No FFDC Code Needed.
            ObjectManager.ffdc.processException(this, cclass, methodName, exception, "1:1565:1.40");

            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this, cclass,
                           methodName,
                           "via PermanentIOException");
            throw new PermanentIOException(this,
                                           exception);
        } // catch (java.io.IOException exception).

        // We cannot check size as we are subclassed.

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass,
                       methodName);
    }
70088
def writeObject(self, obj, is_proxy=False):
        
        if self.use_proxies and not is_proxy:
            self.writeProxy(obj)

            return

        self.stream.write(TYPE_OBJECT)

        ref = self.context.getObjectReference(obj)

        if ref != -1:
            self._writeInteger(ref << 1)

            return

        self.context.addObject(obj)

        # object is not referenced, serialise it
        kls = obj.__class__
        definition = self.context.getClass(kls)
        alias = None
        class_ref = False # if the class definition is a reference

        if definition:
            class_ref = True
            alias = definition.alias
        else:
            alias = self.context.getClassAlias(kls)
            definition = ClassDefinition(alias)

            self.context.addClass(definition, alias.klass)

        if class_ref:
            self.stream.write(definition.reference)
        else:
            ref = 0

            if definition.encoding != ObjectEncoding.EXTERNAL:
                ref += definition.attr_len << 4

            final_reference = encode_int(ref | definition.encoding << 2 |
                REFERENCE_BIT << 1 | REFERENCE_BIT)

            self.stream.write(final_reference)

            definition.reference = encode_int(
                definition.reference << 2 | REFERENCE_BIT)

            if alias.anonymous:
                self.stream.write('\x01')
            else:
                self.serialiseString(alias.alias)

            # work out what the final reference for the class will be.
            # this is okay because the next time an object of the same
            # class is encoded, class_ref will be True and never get here
            # again.

        if alias.external:
            obj.__writeamf__(DataOutput(self))

            return

        attrs = alias.getEncodableAttributes(obj, codec=self)

        if alias.static_attrs:
            if not class_ref:
                [self.serialiseString(attr) for attr in alias.static_attrs]

            for attr in alias.static_attrs:
                value = attrs.pop(attr)

                self.writeElement(value)

            if definition.encoding == ObjectEncoding.STATIC:
                return

        if definition.encoding == ObjectEncoding.DYNAMIC:
            if attrs:
                for attr, value in attrs.iteritems():
                    if type(attr) in python.int_types:
                        attr = str(attr)

                    self.serialiseString(attr)
                    self.writeElement(value)

            self.stream.write('\x01')
12135
public void writeObject(Object value) throws UnsupportedEncodingException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "writeObject", value);
    getBodyList().add(value);
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "writeObject");
  }
320899
def make_response(obj):
    """"""
    if obj is None:
        raise TypeError("Handler return value cannot be None.")
    if isinstance(obj, Response):
        return obj
    return Response(200, body=obj)
891695
private static void writeObject(Object object, CharBuf buffer) {
        if (object == null) {
            buffer.addNull();
        } else {
            Class<?> objectClass = object.getClass();

            if (CharSequence.class.isAssignableFrom(objectClass)) { // Handle String, StringBuilder, GString and other CharSequence implementations
                writeCharSequence((CharSequence) object, buffer);
            } else if (objectClass == Boolean.class) {
                buffer.addBoolean((Boolean) object);
            } else if (Number.class.isAssignableFrom(objectClass)) {
                writeNumber(objectClass, (Number) object, buffer);
            } else if (Date.class.isAssignableFrom(objectClass)) {
                writeDate((Date) object, buffer);
            } else if (Calendar.class.isAssignableFrom(objectClass)) {
                writeDate(((Calendar) object).getTime(), buffer);
            } else if (Map.class.isAssignableFrom(objectClass)) {
                writeMap((Map) object, buffer);
            } else if (Iterable.class.isAssignableFrom(objectClass)) {
                writeIterator(((Iterable<?>) object).iterator(), buffer);
            } else if (Iterator.class.isAssignableFrom(objectClass)) {
                writeIterator((Iterator) object, buffer);
            } else if (objectClass == Character.class) {
                buffer.addJsonEscapedString(Chr.array((Character) object));
            } else if (objectClass == URL.class) {
                buffer.addJsonEscapedString(object.toString());
            } else if (objectClass == UUID.class) {
                buffer.addQuoted(object.toString());
            } else if (Closure.class.isAssignableFrom(objectClass)) {
                writeMap(JsonDelegate.cloneDelegateAndGetContent((Closure<?>) object), buffer);
            } else if (Expando.class.isAssignableFrom(objectClass)) {
                writeMap(((Expando) object).getProperties(), buffer);
            } else if (Enumeration.class.isAssignableFrom(objectClass)) {
                List<?> list = Collections.list((Enumeration<?>) object);
                writeIterator(list.iterator(), buffer);
            } else if (objectClass.isArray()) {
                writeArray(objectClass, object, buffer);
            } else if (Enum.class.isAssignableFrom(objectClass)) {
                buffer.addQuoted(((Enum<?>) object).name());
            } else {
                Map<?, ?> properties = DefaultGroovyMethods.getProperties(object);
                properties.remove("class");
                properties.remove("declaringClass");
                properties.remove("metaClass");
                writeMap(properties, buffer);
            }
        }
    }
648037
public void writeObject(Object obj, AbstractHessianOutput out) 
        throws IOException {
    	
        if (out.addRef(obj)) {
            return;
        }
	    
        Class< ? > cl = obj.getClass();
	    
        try {
            if (writeReplace != null) {
                Object repl = writeReplace.invoke(obj, new Object[0]);

                out.removeRef(obj);

                out.writeObject(repl);

                out.replaceRef(repl, obj);

                return;
            }
        } catch (Exception e) {
            log.log(Level.FINE, e.toString(), e);
        }

        int ref = out.writeObjectBegin(cl.getName());

        if (ref < -1) {
	    // Hessian 1.1 uses a map
	      
            for (int i = 0; i < localMethods.length; i++) {
                Object value = null;

                try {
                    value = localMethods[i].invoke(obj, (Object []) null);
                } catch (Exception e) {
                    log.log(Level.FINE, e.toString(), e);
                }
		
                if (!LazyUtil.isPropertyInitialized(value)) {
                    continue;
                }
		
                out.writeString(localNames[i]);
		
                out.writeObject(value);
            }
	      
            out.writeMapEnd();
        } else {
            if (ref == -1) {
                out.writeInt(localNames.length);
		
                for (int i = 0; i < localNames.length; i++) {
                    out.writeString(localNames[i]);
                }
                out.writeObjectBegin(cl.getName());
            }

            for (int i = 0; i < localMethods.length; i++) {
                Object value = null;

                try {
                    value = localMethods[i].invoke(obj, (Object []) null);
                } catch (Exception e) {
                    log.log(Level.FINER, e.toString(), e);
                }
		
                if (!LazyUtil.isPropertyInitialized(value)) {
                    continue;
                }
		
                out.writeObject(value);
            }
        }
    }
1188899
protected void writeArbitraryObject(Object object) {
        log.debug("writeObject");
        // If we need to serialize class information...
        Class<?> objectClass = object.getClass();
        if (!objectClass.isAnnotationPresent(Anonymous.class)) {
            // Write out start object marker for class name
            buf.put(AMF.TYPE_CLASS_OBJECT);
            putString(buf, Serializer.getClassName(objectClass));
        } else {
            // Write out start object marker without class name
            buf.put(AMF.TYPE_OBJECT);
        }
        // Iterate thru fields of an object to build "name-value" map from it
        for (Field field : objectClass.getFields()) {
            String fieldName = field.getName();
            log.debug("Field: {} class: {}", field, objectClass);
            // Check if the Field corresponding to the getter/setter pair is transient
            if (!serializeField(objectClass, fieldName, field, null)) {
                continue;
            }
            Object value;
            try {
                // Get field value
                value = field.get(object);
            } catch (IllegalAccessException err) {
                // Swallow on private and protected properties access exception
                continue;
            }
            // Write out prop name
            putString(buf, fieldName);
            // Write out
            Serializer.serialize(this, field, null, object, value);
        }
        // write out end of object marker
        buf.put(AMF.END_OF_OBJECT_SEQUENCE);
    }
166068
def _write_wrapper(self, name):
        
        io_attr = getattr(self._io, name)

        def write_wrapper(*args, **kwargs):
            """Wrap all write calls to the stream object."""
            ret_value = io_attr(*args, **kwargs)
            if not IS_PY2:
                return ret_value

        return write_wrapper
408339
def writeProxy(self, obj):
        
        proxy = self.context.getProxyForObject(obj)

        self.writeObject(proxy, is_proxy=True)
844211
private void readObject(final ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
        @SuppressWarnings("unchecked") // Will throw CCE here if not correct
        final
        L[] srcListeners = (L[]) objectInputStream.readObject();

        this.listeners = new CopyOnWriteArrayList<>(srcListeners);

        @SuppressWarnings("unchecked") // Will throw CCE here if not correct
        final
        Class<L> listenerInterface = (Class<L>) srcListeners.getClass().getComponentType();

        initializeTransientFields(listenerInterface, Thread.currentThread().getContextClassLoader());
    }
679719
public static void recordInstance(Object obj) {
		// obj will be a ClassPropertyFetcher instance
		System.err.println("new instance queued " + System.identityHashCode(obj));
		// TODO urgent - race condition here, can create Co-modification problem if adding whilst another thread is processing
		classPropertyFetcherInstances.add(new WeakReference<Object>(obj, rq));
	}
942804
private ByteBuf writeResponse(ByteBuf buffer, Object request, ThreadContext context) {
    context.serializer().writeObject(request, OUTPUT.get().setByteBuf(buffer));
    return buffer;
  }
1094379
public void writeObject (Output output, Object object) {
		if (output == null) throw new IllegalArgumentException("output cannot be null.");
		if (object == null) throw new IllegalArgumentException("object cannot be null.");
		beginObject();
		try {
			if (references && writeReferenceOrNull(output, object, false)) return;
			if (TRACE || (DEBUG && depth == 1)) log("Write", object, output.position());
			getRegistration(object.getClass()).getSerializer().write(this, output, object);
		} finally {
			if (--depth == 0 && autoReset) reset();
		}
	}
876762
private static Object makeClientWrapper(Class<?> clientType,String clientId,Class<? extends InvokeHandler> handlerClass){
        String clientName = clientType.getSimpleName();
        long id = WRAPPER_COUNTER.getAndIncrement();
        if(clientType==DCW.class){
            throw new IllegalArgumentException("not support generate wrapper for interface "+clientName);
        }
        if(!clientType.isInterface()){
            throw new IllegalArgumentException("only support interface to generate wrapper,but type "+clientName+" is not interface");
        }
        JavassistClassGenerator generator = JavassistClassGenerator.newInstance(clientType.getClassLoader());
        generator.addInterface(clientType.getName());
        generator.addInterface(DCW.class.getName());
        StringBuilder className = new StringBuilder();
        className.append(clientType.getSimpleName()).append("$DCW").append(id);
        generator.setClassName(className.toString());
        Method[] methods = clientType.getDeclaredMethods();
        StringBuilder methodCode = new StringBuilder();
        for(Method method:methods){
            methodCode.append("public ");
            Class<?> returnType = method.getReturnType();
            Class<?>[] argsTypes = method.getParameterTypes();
            if(returnType== Void.TYPE){
                methodCode.append("void ");
            }else{
                methodCode.append(returnType.getName()).append(" ");
            }
            methodCode.append(method.getName()).append("(");
            //append arguments
            if(argsTypes.length!=0){
                for(int i=0;i<argsTypes.length;i++){
                    methodCode.append(argsTypes[i].getName()).append(" arg").append(i).append(",");
                }
                methodCode.setLength(methodCode.length()-1);
            }
            Class<?>[] exceptionTypes = method.getExceptionTypes();
            methodCode.append(")");
            if(exceptionTypes.length!=0){
                methodCode.append("throws ");
                for(Class<?> exceptionType:exceptionTypes){
                    methodCode.append(exceptionType.getName()).append(",");
                }
                methodCode.setLength(methodCode.length()-1);
            }
            methodCode.append("{");
            methodCode.append("try{");
            //append method body
            //handle invoke before
            if(argsTypes.length==0){
                methodCode.append("invokeHandler.beforeInvoke(clientType,\"" + method.getName() + "\",null);");
            }else{
                methodCode.append("invokeHandler.beforeInvoke(clientType,\"" + method.getName() + "\",$args);");
            }
            //handle invoke complete
            if(returnType== Void.TYPE){
                methodCode.append("(($w)clientRef).").append(method.getName()).append("($$);");
                if(argsTypes.length==0){
                    methodCode.append("invokeHandler.completeInvoke(clientType,\"" + method.getName() + "\",null,null);");
                }else{
                    methodCode.append("invokeHandler.completeInvoke(clientType,\"" + method.getName() + "\",null,$args);");
                }
            }else{
                methodCode.append("Object result=(($w)clientRef).").append(method.getName()).append("($$);");
                if(argsTypes.length==0){
                    methodCode.append("invokeHandler.completeInvoke(clientType,\"" + method.getName() + "\",(Object)result,null);");
                }else{
                    methodCode.append("invokeHandler.completeInvoke(clientType,\"" + method.getName() + "\",(Object)result,$args);");
                }
                methodCode.append("return ($r)result;");
            }
            methodCode.append("}catch(Throwable t){");
            //handle invoke exception
            if(argsTypes.length==0){
                methodCode.append("invokeHandler.caughtException(clientType,\"" + method.getName() + "\",t,null);");
            }else{
                methodCode.append("invokeHandler.caughtException(clientType,\"" + method.getName() + "\",t,$args);");
            }

            methodCode.append("throw new ").append(InvokeTargetException.class.getName()).append("(clientType,\""+method.getName()+"\",t);");
            methodCode.append("}");
            methodCode.append("}");
            generator.addMethod(methodCode.toString());
            methodCode.setLength(0);
        }
        generator.addField("public static "+clientType.getName()+" clientRef;");
        generator.addField("public static "+InvokeHandler.class.getName()+" invokeHandler;");
        generator.addField("public static "+Class.class.getName()+" clientType;");
        Class<?> clazz = generator.toClass();
        try {
            ReferenceConfig config = new ReferenceConfig();
            config.setId(clientId);
            config.setCheck(false);
            config.setInterface(clientType.getName());
            clazz.getField("clientRef").set(null,config.get());
            if(!HANDLER_CACHE.containsKey(handlerClass)){
                HANDLER_CACHE.putIfAbsent(handlerClass,handlerClass.newInstance());
            }
            clazz.getField("invokeHandler").set(null,HANDLER_CACHE.get(handlerClass));
            clazz.getField("clientType").set(null,clientType);
            return clazz.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
    }
1205926
public static void writeObject(Serializable toSave, OutputStream writeTo) {
        try {
            ObjectOutputStream os = new ObjectOutputStream(writeTo);
            os.writeObject(toSave);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }