Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.ser.impl;
  
  import java.util.List;
  
  
This is an optimized serializer for Lists that can be efficiently traversed by index (as opposed to others, such as java.util.LinkedList that can not}.
 
 public final class IndexedListSerializer
     extends AsArraySerializerBase<List<?>>
 {
     public IndexedListSerializer(JavaType elemTypeboolean staticTypingTypeSerializer vts,
             BeanProperty propertyJsonSerializer<ObjectvalueSerializer)
     {
         super(List.classelemTypestaticTypingvtspropertyvalueSerializer);
     }
 
             BeanProperty propertyTypeSerializer vtsJsonSerializer<?> valueSerializer)
     {
         super(srcpropertyvtsvalueSerializer);
     }
 
     @Override
     public IndexedListSerializer withResolved(BeanProperty property,
             TypeSerializer vtsJsonSerializer<?> elementSerializer) {
         return new IndexedListSerializer(thispropertyvtselementSerializer);
     }
 
     @Override
     public boolean isEmpty(List<?> value) {
         return (value == null) || value.isEmpty();
     }
 
     @Override
     public boolean hasSingleElement(List<?> value) {
         return (value.size() == 1);
     }
 
     @Override
     }
     
     @Override
     public void serializeContents(List<?> valueJsonGenerator jgenSerializerProvider provider)
         throws IOExceptionJsonGenerationException
     {
         if ( != null) {
             serializeContentsUsing(valuejgenprovider);
             return;
         }
         if ( != null) {
             serializeTypedContents(valuejgenprovider);
             return;
         }
         final int len = value.size();
         if (len == 0) {
             return;
         }
         int i = 0;
         try {
             PropertySerializerMap serializers = ;
             for (; i < len; ++i) {
                 Object elem = value.get(i);
                 if (elem == null) {
                     provider.defaultSerializeNull(jgen);
                 } else {
                     Class<?> cc = elem.getClass();
                     JsonSerializer<Objectserializer = serializers.serializerFor(cc);
                     if (serializer == null) {
                         // To fix [JACKSON-508]
                         if (.hasGenericTypes()) {
                             serializer = _findAndAddDynamic(serializers,
                                     provider.constructSpecializedType(cc), provider);
                         } else {
                             serializer = _findAndAddDynamic(serializersccprovider);
                         }
                         serializers = ;
                     }
                     serializer.serialize(elemjgenprovider);
                 }
             }
         } catch (Exception e) {
             // [JACKSON-55] Need to add reference information
             wrapAndThrow(providerevaluei);
        }
    }
    
    public void serializeContentsUsing(List<?> valueJsonGenerator jgenSerializerProvider provider,
            JsonSerializer<Objectser)
        throws IOExceptionJsonGenerationException
    {
        final int len = value.size();
        if (len == 0) {
            return;
        }
        final TypeSerializer typeSer = ;
        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(elemjgenprovider);
                } else {
                    ser.serializeWithType(elemjgenprovidertypeSer);
                }
            } catch (Exception e) {
                // [JACKSON-55] Need to add reference information
                wrapAndThrow(providerevaluei);
            }
        }
    }
    public void serializeTypedContents(List<?> valueJsonGenerator jgenSerializerProvider provider)
        throws IOExceptionJsonGenerationException
    {
        final int len = value.size();
        if (len == 0) {
            return;
        }
        int i = 0;
        try {
            final TypeSerializer typeSer = ;
            PropertySerializerMap serializers = ;
            for (; i < len; ++i) {
                Object elem = value.get(i);
                if (elem == null) {
                    provider.defaultSerializeNull(jgen);
                } else {
                    Class<?> cc = elem.getClass();
                    JsonSerializer<Objectserializer = serializers.serializerFor(cc);
                    if (serializer == null) {
                        // To fix [JACKSON-508]
                        if (.hasGenericTypes()) {
                            serializer = _findAndAddDynamic(serializers,
                                    provider.constructSpecializedType(cc), provider);
                        } else {
                            serializer = _findAndAddDynamic(serializersccprovider);
                        }
                        serializers = ;
                    }
                    serializer.serializeWithType(elemjgenprovidertypeSer);
                }
            }
        } catch (Exception e) {
            // [JACKSON-55] Need to add reference information
            wrapAndThrow(providerevaluei);
        }
    }
New to GrepCode? Check out our FAQ X