@Override
 public void serializeContents(
     Iterator<?> value, JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonGenerationException {
   if (value.hasNext()) {
     final TypeSerializer typeSer = _valueTypeSerializer;
     JsonSerializer<Object> prevSerializer = null;
     Class<?> prevClass = null;
     do {
       Object elem = value.next();
       if (elem == null) {
         provider.defaultSerializeNull(jgen);
       } else {
         // Minor optimization to avoid most lookups:
         Class<?> cc = elem.getClass();
         JsonSerializer<Object> currSerializer;
         if (cc == prevClass) {
           currSerializer = prevSerializer;
         } else {
           currSerializer = provider.findValueSerializer(cc, _property);
           prevSerializer = currSerializer;
           prevClass = cc;
         }
         if (typeSer == null) {
           currSerializer.serialize(elem, jgen, provider);
         } else {
           currSerializer.serializeWithType(elem, jgen, provider, typeSer);
         }
       }
     } while (value.hasNext());
   }
 }
 @Override
 public void serializeContents(List<?> value, JsonGenerator jgen, SerializerProvider provider)
     throws IOException, JsonGenerationException {
   if (_elementSerializer != null) {
     serializeContentsUsing(value, jgen, provider, _elementSerializer);
     return;
   }
   if (_valueTypeSerializer != null) {
     serializeTypedContents(value, jgen, provider);
     return;
   }
   final int len = value.size();
   if (len == 0) {
     return;
   }
   int i = 0;
   try {
     PropertySerializerMap serializers = _dynamicSerializers;
     for (; i < len; ++i) {
       Object elem = value.get(i);
       if (elem == null) {
         provider.defaultSerializeNull(jgen);
       } else {
         Class<?> cc = elem.getClass();
         JsonSerializer<Object> serializer = serializers.serializerFor(cc);
         if (serializer == null) {
           // To fix [JACKSON-508]
           if (_elementType.hasGenericTypes()) {
             serializer =
                 _findAndAddDynamic(
                     serializers, provider.constructSpecializedType(_elementType, cc), provider);
           } else {
             serializer = _findAndAddDynamic(serializers, cc, provider);
           }
           serializers = _dynamicSerializers;
         }
         serializer.serialize(elem, jgen, provider);
       }
     }
   } catch (Exception e) {
     // [JACKSON-55] Need to add reference information
     wrapAndThrow(provider, e, value, i);
   }
 }
 public void serializeContentsUsing(
     List<?> value, JsonGenerator jgen, SerializerProvider provider, JsonSerializer<Object> ser)
     throws IOException, JsonGenerationException {
   final int len = value.size();
   if (len == 0) {
     return;
   }
   final TypeSerializer typeSer = _valueTypeSerializer;
   for (int i = 0; i < len; ++i) {
     Object elem = value.get(i);
     try {
       if (elem == null) {
         provider.defaultSerializeNull(jgen);
       } else if (typeSer == null) {
         ser.serialize(elem, jgen, provider);
       } else {
         ser.serializeWithType(elem, jgen, provider, typeSer);
       }
     } catch (Exception e) {
       // [JACKSON-55] Need to add reference information
       wrapAndThrow(provider, e, value, i);
     }
   }
 }