Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind.ser.std;
 
 
 
public class IterableSerializer
    extends AsArraySerializerBase<Iterable<?>>
    public IterableSerializer(JavaType elemTypeboolean staticTyping,
            TypeSerializer vtsBeanProperty property)
    {
        super(Iterable.classelemTypestaticTypingvtspropertynull);
    }
    public IterableSerializer(IterableSerializer srcBeanProperty property,
            TypeSerializer vtsJsonSerializer<?> valueSerializer)
    {
        super(srcpropertyvtsvalueSerializer);
    }
    
    @Override
        return new IterableSerializer(vts);
    }
    @Override
    public IterableSerializer withResolved(BeanProperty property,
            TypeSerializer vtsJsonSerializer<?> elementSerializer) {
        return new IterableSerializer(thispropertyvtselementSerializer);
    }
    
    @Override
    public boolean isEmpty(Iterable<?> value) {
        // Not really good way to implement this, but has to do for now:
        return (value == null) || !value.iterator().hasNext();
    }
    @Override
    public boolean hasSingleElement(Iterable<?> value) {
        // no really good way to determine (without consuming iterator), so:
        return false;
    }
    
    @Override
    public void serializeContents(Iterable<?> valueJsonGenerator jgenSerializerProvider provider)
        throws IOExceptionJsonGenerationException
    {
        Iterator<?> it = value.iterator();
        if (it.hasNext()) {
            final TypeSerializer typeSer = ;
            JsonSerializer<ObjectprevSerializer = null;
            Class<?> prevClass = null;
            
            do {
                Object elem = it.next();
                if (elem == null) {
                    provider.defaultSerializeNull(jgen);
                } else {
                    // Minor optimization to avoid most lookups:
                    Class<?> cc = elem.getClass();
                    JsonSerializer<ObjectcurrSerializer;
                    if (cc == prevClass) {
                        currSerializer = prevSerializer;
                    } else {
                        currSerializer = provider.findValueSerializer(cc);
                        prevSerializer = currSerializer;
                        prevClass = cc;
                    }
                    if (typeSer == null) {
                        currSerializer.serialize(elemjgenprovider);
                    } else {
                        currSerializer.serializeWithType(elemjgenprovidertypeSer);
                    }
                }
            } while (it.hasNext());
        }
    }
New to GrepCode? Check out our FAQ X