private static boolean serializeElement ( Object element , Deque < SerializationFrame > stack , DataOutputStream dOut , Map < String , AbstractDataMarshaller < ? > > marshallerMap , Map < SerializedObject , SerializedObject > serializedObjects , SerializedObject testSerializedObject , boolean ignoreMissingMarshallers ) throws IOException { if ( element instanceof List ) { stack . push ( new ListSerializationFrame ( element , ( List < ? > ) element ) ) ; return true ; } else if ( element == null || isPrimitiveOrString ( element ) ) { serializePrimitive ( dOut , element ) ; } else { //unmarshalled deSerializedObject or data node testSerializedObject . object = element ; if ( serializedObjects . containsKey ( testSerializedObject ) ) { final SerializedObject serializedObject = serializedObjects . get ( testSerializedObject ) ; serializeReference ( serializedObject , dOut ) ; } else { DataNodeSerializationFrame dataNodeFrame ; if ( element instanceof DataNode ) { dataNodeFrame = new DataNodeSerializationFrame ( element , ( DataNode ) element ) ; } else { final DataNode marshalledObject = marshalObject ( marshallerMap , element ) ; if ( marshalledObject != null ) { dataNodeFrame = new DataNodeSerializationFrame ( element , marshalledObject ) ; } else { //we have no marshaller for the given object - now either raise an exception //or set the value to null ... if ( ! ignoreMissingMarshallers ) { throw new IllegalStateException ( "No serializer defined for class " + element . getClass ( ) . getCanonicalName ( ) ) ; } else { //ignore and just store null value serializePrimitive ( dOut , null ) ; return false ; } } } stack . push ( dataNodeFrame ) ; return true ; } } return false ; }
processes one element and either serializes it directly to the stream or pushes a corresponding frame to the stack .