public void serializeTypedContents(
     Object[] paramArrayOfObject,
     JsonGenerator paramJsonGenerator,
     SerializerProvider paramSerializerProvider)
     throws IOException {
   int k = paramArrayOfObject.length;
   TypeSerializer localTypeSerializer = this._valueTypeSerializer;
   int j = 0;
   int i = 0;
   Object localObject1 = null;
   for (; ; ) {
     try {
       PropertySerializerMap localPropertySerializerMap = this._dynamicSerializers;
       if (i < k) {
         Object localObject2 = paramArrayOfObject[i];
         if (localObject2 == null) {
           localObject1 = localObject2;
           j = i;
           paramSerializerProvider.defaultSerializeNull(paramJsonGenerator);
         } else {
           localObject1 = localObject2;
           j = i;
           Class localClass = localObject2.getClass();
           localObject1 = localObject2;
           j = i;
           JsonSerializer localJsonSerializer2 =
               localPropertySerializerMap.serializerFor(localClass);
           JsonSerializer localJsonSerializer1 = localJsonSerializer2;
           if (localJsonSerializer2 == null) {
             localObject1 = localObject2;
             j = i;
             localJsonSerializer1 =
                 _findAndAddDynamic(
                     localPropertySerializerMap, localClass, paramSerializerProvider);
           }
           localObject1 = localObject2;
           j = i;
           localJsonSerializer1.serializeWithType(
               localObject2, paramJsonGenerator, paramSerializerProvider, localTypeSerializer);
         }
       }
     } catch (IOException paramArrayOfObject) {
       throw paramArrayOfObject;
     } catch (Exception paramArrayOfObject) {
       if (((paramArrayOfObject instanceof InvocationTargetException))
           && (paramArrayOfObject.getCause() != null)) {
         paramArrayOfObject = paramArrayOfObject.getCause();
         continue;
       }
       if ((paramArrayOfObject instanceof Error)) {
         throw ((Error) paramArrayOfObject);
       }
       throw JsonMappingException.wrapWithPath(paramArrayOfObject, localObject1, j);
     }
     return;
     i += 1;
   }
 }
Ejemplo n.º 2
0
  /** Method called to serialize fields, when the value type is not statically known. */
  public void serializeFields(Map<?, ?> value, JsonGenerator jgen, SerializerProvider provider)
      throws IOException, JsonGenerationException {
    // If value type needs polymorphic type handling, some more work needed:
    if (_valueTypeSerializer != null) {
      serializeTypedFields(value, jgen, provider);
      return;
    }
    final JsonSerializer<Object> keySerializer = _keySerializer;

    final HashSet<String> ignored = _ignoredEntries;
    final boolean skipNulls = !provider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES);

    PropertySerializerMap serializers = _dynamicValueSerializers;

    for (Map.Entry<?, ?> entry : value.entrySet()) {
      Object valueElem = entry.getValue();
      // First, serialize key
      Object keyElem = entry.getKey();
      if (keyElem == null) {
        provider.findNullKeySerializer(_keyType, _property).serialize(null, jgen, provider);
      } else {
        // [JACKSON-314] skip entries with null values?
        if (skipNulls && valueElem == null) continue;
        // One twist: is entry ignorable? If so, skip
        if (ignored != null && ignored.contains(keyElem)) continue;
        keySerializer.serialize(keyElem, jgen, provider);
      }

      // And then value
      if (valueElem == null) {
        provider.defaultSerializeNull(jgen);
      } else {
        Class<?> cc = valueElem.getClass();
        JsonSerializer<Object> serializer = serializers.serializerFor(cc);
        if (serializer == null) {
          if (_valueType.hasGenericTypes()) {
            serializer =
                _findAndAddDynamic(
                    serializers, provider.constructSpecializedType(_valueType, cc), provider);
          } else {
            serializer = _findAndAddDynamic(serializers, cc, provider);
          }
          serializers = _dynamicValueSerializers;
        }
        try {
          serializer.serialize(valueElem, jgen, provider);
        } catch (Exception e) {
          // [JACKSON-55] Need to add reference information
          String keyDesc = "" + keyElem;
          wrapAndThrow(provider, e, value, keyDesc);
        }
      }
    }
  }
 /** Helper method that encapsulates logic of retrieving and caching required serializer. */
 protected final JsonSerializer<Object> _findCachedSerializer(
     SerializerProvider provider, Class<?> type) throws JsonMappingException {
   JsonSerializer<Object> ser = _dynamicSerializers.serializerFor(type);
   if (ser == null) {
     ser = _findSerializer(provider, type, _property);
     if (_unwrapper != null) {
       ser = ser.unwrappingSerializer(_unwrapper);
     }
     _dynamicSerializers = _dynamicSerializers.newWith(type, ser);
   }
   return ser;
 }
Ejemplo n.º 4
0
 /** @since 2.5 */
 @SuppressWarnings("unchecked")
 protected MapSerializer(
     Set<String> ignoredEntries,
     JavaType keyType,
     JavaType valueType,
     boolean valueTypeIsStatic,
     TypeSerializer vts,
     JsonSerializer<?> keySerializer,
     JsonSerializer<?> valueSerializer) {
   super(Map.class, false);
   _ignoredEntries =
       ((ignoredEntries == null) || ignoredEntries.isEmpty()) ? null : ignoredEntries;
   _keyType = keyType;
   _valueType = valueType;
   _valueTypeIsStatic = valueTypeIsStatic;
   _valueTypeSerializer = vts;
   _keySerializer = (JsonSerializer<Object>) keySerializer;
   _valueSerializer = (JsonSerializer<Object>) valueSerializer;
   _dynamicValueSerializers = PropertySerializerMap.emptyForProperties();
   _property = null;
   _filterId = null;
   _sortKeys = false;
   _suppressableValue = null;
   _suppressNulls = false;
 }
Ejemplo n.º 5
0
 protected final JsonSerializer<Object> _findAndAddDynamic(
     PropertySerializerMap map, JavaType type, SerializerProvider provider)
     throws JsonMappingException {
   PropertySerializerMap.SerializerAndMapResult result =
       map.findAndAddSerializer(type, provider, _property);
   if (map != result.map) {
     _dynamicValueSerializers = result.map;
   }
   return result.serializer;
 }
Ejemplo n.º 6
0
 protected final JsonSerializer<Object> _findAndAddDynamic(
     PropertySerializerMap map, Class<?> type, SerializerProvider provider)
     throws JsonMappingException {
   PropertySerializerMap.SerializerAndMapResult result =
       map.findAndAddSerializer(type, provider, _property);
   // did we get a new map of serializers? If so, start using it
   if (map != result.map) {
     _dynamicValueSerializers = result.map;
   }
   return result.serializer;
 }
 @SuppressWarnings("unchecked")
 public GuavaOptionalSerializer(
     ReferenceType fullType, TypeSerializer vts, JsonSerializer<?> valueSer) {
   super(fullType);
   _referredType = fullType.getReferencedType();
   _property = null;
   _valueTypeSerializer = vts;
   _valueSerializer = (JsonSerializer<Object>) valueSer;
   _unwrapper = null;
   _contentInclusion = null;
   _dynamicSerializers = PropertySerializerMap.emptyForProperties();
 }
 public ObjectArraySerializer(
     JavaType paramJavaType,
     boolean paramBoolean,
     TypeSerializer paramTypeSerializer,
     JsonSerializer<Object> paramJsonSerializer) {
   super(Object[].class);
   this._elementType = paramJavaType;
   this._staticTyping = paramBoolean;
   this._valueTypeSerializer = paramTypeSerializer;
   this._dynamicSerializers = PropertySerializerMap.emptyForProperties();
   this._elementSerializer = paramJsonSerializer;
 }
 protected final JsonSerializer<Object> _findAndAddDynamic(
     PropertySerializerMap paramPropertySerializerMap,
     Class<?> paramClass,
     SerializerProvider paramSerializerProvider)
     throws JsonMappingException {
   paramClass =
       paramPropertySerializerMap.findAndAddSecondarySerializer(
           paramClass, paramSerializerProvider, this._property);
   if (paramPropertySerializerMap != paramClass.map) {
     this._dynamicSerializers = paramClass.map;
   }
   return paramClass.serializer;
 }
Ejemplo n.º 10
0
 private final JsonSerializer<Object> _findSerializer(SerializerProvider provider, Object value)
     throws JsonMappingException {
   final Class<?> cc = value.getClass();
   JsonSerializer<Object> valueSer = _dynamicValueSerializers.serializerFor(cc);
   if (valueSer != null) {
     return valueSer;
   }
   if (_valueType.hasGenericTypes()) {
     return _findAndAddDynamic(
         _dynamicValueSerializers, provider.constructSpecializedType(_valueType, cc), provider);
   }
   return _findAndAddDynamic(_dynamicValueSerializers, cc, provider);
 }
Ejemplo n.º 11
0
 @SuppressWarnings("unchecked")
 protected MapSerializer(
     HashSet<String> ignoredEntries,
     JavaType keyType,
     JavaType valueType,
     boolean valueTypeIsStatic,
     TypeSerializer vts,
     JsonSerializer<?> keySerializer,
     JsonSerializer<?> valueSerializer) {
   super(Map.class, false);
   _ignoredEntries = ignoredEntries;
   _keyType = keyType;
   _valueType = valueType;
   _valueTypeIsStatic = valueTypeIsStatic;
   _valueTypeSerializer = vts;
   _keySerializer = (JsonSerializer<Object>) keySerializer;
   _valueSerializer = (JsonSerializer<Object>) valueSerializer;
   _dynamicValueSerializers = PropertySerializerMap.emptyMap();
   _property = null;
 }