/**
  * Enter description here...
  *
  * @param SerializationStreamWriter $streamWriter
  * @param array $instance
  * @param MappedClass $instanceClass
  * @throws SerializationException
  */
 public static function serialize(SerializationStreamWriter $streamWriter, $instance, MappedClass $instanceClass, $consuming_type, $name)
 {
     if ($consuming_type == 0) {
         $size = $instance->size();
         $streamWriter->writeInt($size);
         $iterator = $instance->getIterator();
         while ($iterator->valid()) {
             $streamWriter->writeObject($iterator->current());
             $iterator->next();
         }
     } else {
         if ($consuming_type == 1) {
             // $instance is array
             $size = count($instance);
             $streamWriter->writeInt($size);
             //for (Object obj : instance) {
             if (!$instanceClass->isGeneric()) {
                 require_once GWTPHP_DIR . '/maps/java/lang/SerializationException.class.php';
                 throw new SerializationException("Error occurred while casting native php array to {$name}: " . "{$name} must be mapped as generic type! add < > to signatures and CRC");
             }
             //			if (!$instanceClass->isGeneric())  {
             //				class_exists('SerializationException') || require(GWTPHP_DIR.'/maps/java/lang/SerializationException.class.php');
             //				throw new SerializationException("ArrayList must be mapped as generic type! add < > to signatures and CRC");
             //			}
             $typeParameters = $instanceClass->getTypeParameters();
             foreach ($instance as $obj) {
                 $streamWriter->writeObject($obj, $typeParameters[0]);
             }
         }
     }
 }
 /**
  *
  * @param SerializationStreamWriter $streamWriter
  * @param HashMap $instance
  * @param MappedClass $instanceClass
  * @throws SerializationException
  */
 public static function serialize(SerializationStreamWriter $streamWriter, $instance, MappedClass $instanceClass)
 {
     if ($instance instanceof HashMap) {
         $size = $instance->size();
         $streamWriter->writeInt($size);
         //assert($instanceClass->isGeneric()); //jesli nie array to zapomniano w gwtphpmap dodacgenericsow
         if ($instanceClass->isGeneric()) {
             $typeParameters = $instanceClass->getTypeParameters();
         } else {
             $typeParameters = array();
         }
         assert(is_array($typeParameters));
         //jesli nie array to zapomniano w gwtphpmap dodacgenericsow
         foreach ($instance->getKeySet() as $key) {
             $streamWriter->writeObject($key, $typeParameters[0]);
             $streamWriter->writeObject($instance->get($key), $typeParameters[1]);
         }
     } else {
         if (is_array($instance)) {
             // $instance is array
             //$size = $instance->size();
             $size = count($instance);
             $streamWriter->writeInt($size);
             //for (Object obj : instance) {
             if (!$instanceClass->isGeneric()) {
                 require_once GWTPHP_DIR . '/maps/java/lang/SerializationException.class.php';
                 throw new SerializationException("Error occurred while casting native php array to HashMap: " . "HashMap must be mapped as generic type! add < > to signatures and CRC");
             }
             $typeParameters = $instanceClass->getTypeParameters();
             if (!isset(HashMap_CustomFieldSerializer::$ACCEPTABLE_KEY_TYPES[$typeParameters[0]->getSignature()])) {
                 require_once GWTPHP_DIR . '/maps/java/lang/SerializationException.class.php';
                 throw new SerializationException("Error occurred while casting native php array to HashMap: " . "HashMap_CustomFieldSerializer serialize only array() where " . "keys object are mapped by one of following types: " . "java.lang.String, java.lang.Byte, java.lang.Character, java.lang.Double, " . "java.lang.Float, java.lang.Integer, java.lang.Long, java.lang.Short, but given: " . $typeParameters[0]->getSignature());
             }
             foreach ($instance as $key => $obj) {
                 $streamWriter->writeObject($key, $typeParameters[0]);
                 $streamWriter->writeObject($obj, $typeParameters[1]);
             }
         } else {
             require_once GWTPHP_DIR . '/maps/java/lang/UnimplementedOperationException.class.php';
             throw new UnimplementedOperationException("HashMap_CustomFieldSerializer serialize type: " + gettype($instance) + " not implemented");
         }
     }
 }
 /**
  *
  * @param SerializationStreamWriter $streamWriter
  * @param HashMap $instance
  * @param MappedClass $instanceClass
  * @throws SerializationException
  */
 public static function serialize(SerializationStreamWriter $streamWriter, $instance, MappedClass $instanceClass)
 {
     ob_start();
     print_r($instance);
     syslog(LOG_DEBUG, "instance = " . ob_get_contents());
     ob_end_clean();
     if ($instance instanceof HashMap) {
         $size = $instance->size();
         $streamWriter->writeInt($size);
         foreach ($instance->getKeySet() as $key) {
             $streamWriter->writeObject($key);
             $streamWriter->writeObject($instance->get($key));
         }
     } else {
         if (is_array($instance)) {
             // $instance is array
             //$size = $instance->size();
             $size = count($instance);
             $streamWriter->writeInt($size);
             $typeParameters = $instanceClass->getTypeParameters();
             //for (Object obj : instance) {
             if (defined('GWTPHP_FORCE_SHOEHORN') and !is_array($typeParameters)) {
                 // Force casting to java.util.HashMap<java.lang.String,java.lang.String>
                 require_once GWTPHP_DIR . '/lang/SimpleMappedClass.class.php';
                 $_class = new SimpleMappedClass();
                 $_class->setClassLoader(GWTPHPContext::getInstance()->getMappedClassLoader()->getClassLoader());
                 $_class->setMappedName("java.lang.String");
                 $_class->setSignature("java.lang.String");
                 $_class->setCRC("2004016611");
                 $typeParameters = array($_class, $_class);
             } else {
                 if (!$instanceClass->isGeneric()) {
                     class_exists('SerializationException') || (require_once GWTPHP_DIR . '/exceptions/SerializationException.class.php');
                     throw new SerializationException("Error occurred while casting native php array to HashMap: " . "HashMap must be mapped as generic type! add < > to signatures and CRC");
                     $typeParameters = $instanceClass->getTypeParameters();
                 }
             }
             if (!isset(HashMap_CustomFieldSerializer::$ACCEPTABLE_KEY_TYPES[$typeParameters[0]->getSignature()])) {
                 class_exists('SerializationException') || (require_once GWTPHP_DIR . '/exceptions/SerializationException.class.php');
                 throw new SerializationException("Error occurred while casting native php array to HashMap: " . "HashMap_CustomFieldSerializer serialize only array() where " . "keys object are mapped by one of following types: " . "java.lang.String, java.lang.Byte, java.lang.Character, java.lang.Double, " . "java.lang.Float, java.lang.Integer, java.lang.Long, java.lang.Short, but given: " . $typeParameters[0]->getSignature());
             }
             foreach ($instance as $key => $obj) {
                 $streamWriter->writeObject($key, $typeParameters[0]);
                 $streamWriter->writeObject($obj, $typeParameters[1]);
             }
         } else {
             if (defined('GWTPHP_FORCE_SHOEHORN')) {
                 // Compatibility hack. :(
                 $streamWriter->writeInt(0);
             } else {
                 throw new UnimplementedOperationException("HashMap_CustomFieldSerializer serialize type: " + gettype($instance) + " not implemented");
             }
         }
     }
 }