/**
   * Method called to serialize fields, when the value type is statically known, so that value
   * serializer is passed and does not need to be fetched from provider.
   */
  public void serializeFieldsUsing(
      Map<?, ?> value, JsonGenerator gen, SerializerProvider provider, JsonSerializer<Object> ser)
      throws IOException {
    final JsonSerializer<Object> keySerializer = _keySerializer;
    final Set<String> ignored = _ignoredEntries;
    final TypeSerializer typeSer = _valueTypeSerializer;

    for (Map.Entry<?, ?> entry : value.entrySet()) {
      Object keyElem = entry.getKey();
      if (ignored != null && ignored.contains(keyElem)) continue;

      if (keyElem == null) {
        provider.findNullKeySerializer(_keyType, _property).serialize(null, gen, provider);
      } else {
        keySerializer.serialize(keyElem, gen, provider);
      }
      final Object valueElem = entry.getValue();
      if (valueElem == null) {
        provider.defaultSerializeNull(gen);
      } else {
        try {
          if (typeSer == null) {
            ser.serialize(valueElem, gen, provider);
          } else {
            ser.serializeWithType(valueElem, gen, provider, typeSer);
          }
        } catch (Exception e) {
          wrapAndThrow(provider, e, value, String.valueOf(keyElem));
        }
      }
    }
  }
 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;
   }
 }
 @Override
 public void serialize(
     ObjectId objectId, BsonGenerator bsonGenerator, SerializerProvider serializerProvider)
     throws IOException {
   if (objectId == null) {
     serializerProvider.defaultSerializeNull(bsonGenerator);
   } else {
     bsonGenerator.writeObjectId(objectId);
   }
 }
Example #4
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);
        }
      }
    }
  }
 @Override
 public void serialize(Symbol value, JsonGenerator gen, SerializerProvider serializerProvider)
     throws IOException {
   if (value == null) {
     serializerProvider.defaultSerializeNull(gen);
   } else if (gen instanceof BsonGenerator) {
     BsonGenerator bgen = (BsonGenerator) gen;
     bgen.writeSymbol(value);
   } else {
     gen.writeString(value.getSymbol());
   }
 }
 private void serializeContentsSlow(
     String[] value, JsonGenerator jgen, SerializerProvider provider, JsonSerializer<Object> ser)
     throws IOException, JsonGenerationException {
   int len = value.length;
   for (int i = 0; i < len; i++) {
     if (value[i] == null) {
       provider.defaultSerializeNull(jgen);
     } else {
       ser.serialize(value[i], jgen, provider);
     }
   }
 }
 @Override
 public void serializeWithType(
     Optional<?> opt, JsonGenerator gen, SerializerProvider provider, TypeSerializer typeSer)
     throws IOException {
   if (!opt.isPresent()) {
     if (_unwrapper == null) {
       provider.defaultSerializeNull(gen);
     }
     return;
   }
   // Otherwise apply type-prefix/suffix, then std serialize:
   typeSer.writeTypePrefixForScalar(opt, gen, Optional.class);
   serialize(opt, gen, provider);
   typeSer.writeTypeSuffixForScalar(opt, gen);
 }
Example #8
0
  protected void serializeTypedFields(
      Map<?, ?> value, JsonGenerator jgen, SerializerProvider provider)
      throws IOException, JsonGenerationException {
    final JsonSerializer<Object> keySerializer = _keySerializer;
    JsonSerializer<Object> prevValueSerializer = null;
    Class<?> prevValueClass = null;
    final HashSet<String> ignored = _ignoredEntries;
    final boolean skipNulls = !provider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES);

    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] also may need to 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> currSerializer;
        if (cc == prevValueClass) {
          currSerializer = prevValueSerializer;
        } else {
          currSerializer = provider.findValueSerializer(cc, _property);
          prevValueSerializer = currSerializer;
          prevValueClass = cc;
        }
        try {
          currSerializer.serializeWithType(valueElem, jgen, provider, _valueTypeSerializer);
        } catch (Exception e) {
          // [JACKSON-55] Need to add reference information
          String keyDesc = "" + keyElem;
          wrapAndThrow(provider, e, value, keyDesc);
        }
      }
    }
  }
 private final void serializeContents(
     List<String> value, JsonGenerator jgen, SerializerProvider provider, int len)
     throws IOException, JsonGenerationException {
   int i = 0;
   try {
     for (; i < len; ++i) {
       String str = value.get(i);
       if (str == null) {
         provider.defaultSerializeNull(jgen);
       } else {
         jgen.writeString(str);
       }
     }
   } catch (Exception e) {
     wrapAndThrow(provider, e, value, i);
   }
 }
 private final void serializeUsingCustom(
     List<String> value, JsonGenerator jgen, SerializerProvider provider, int len)
     throws IOException, JsonGenerationException {
   int i = 0;
   try {
     final JsonSerializer<String> ser = _serializer;
     for (i = 0; i < len; ++i) {
       String str = value.get(i);
       if (str == null) {
         provider.defaultSerializeNull(jgen);
       } else {
         ser.serialize(str, jgen, provider);
       }
     }
   } catch (Exception e) {
     wrapAndThrow(provider, e, value, i);
   }
 }
 public void serializeContentsUsing(
     Object[] paramArrayOfObject,
     JsonGenerator paramJsonGenerator,
     SerializerProvider paramSerializerProvider,
     JsonSerializer<Object> paramJsonSerializer)
     throws IOException {
   int j = paramArrayOfObject.length;
   TypeSerializer localTypeSerializer = this._valueTypeSerializer;
   int i = 0;
   for (; ; ) {
     Object localObject;
     if (i < j) {
       localObject = paramArrayOfObject[i];
       if (localObject == null) {}
       try {
         paramSerializerProvider.defaultSerializeNull(paramJsonGenerator);
       } catch (IOException paramArrayOfObject) {
         throw paramArrayOfObject;
         paramJsonSerializer.serializeWithType(
             localObject, paramJsonGenerator, paramSerializerProvider, localTypeSerializer);
       } catch (Exception paramArrayOfObject) {
         while (((paramArrayOfObject instanceof InvocationTargetException))
             && (paramArrayOfObject.getCause() != null)) {
           paramArrayOfObject = paramArrayOfObject.getCause();
         }
         if (!(paramArrayOfObject instanceof Error)) {
           break label108;
         }
         throw ((Error) paramArrayOfObject);
         throw JsonMappingException.wrapWithPath(paramArrayOfObject, localObject, i);
       }
       if (localTypeSerializer == null) {
         paramJsonSerializer.serialize(localObject, paramJsonGenerator, paramSerializerProvider);
         break label118;
       }
     }
     label108:
     return;
     label118:
     i += 1;
   }
 }
 @Override
 public void serialize(Optional<?> opt, JsonGenerator gen, SerializerProvider provider)
     throws IOException {
   if (!opt.isPresent()) {
     // 22-Oct-2015, tatu: With unwrapping we can not serialize value, just key/value pairs so:
     if (_unwrapper == null) {
       provider.defaultSerializeNull(gen);
     }
     return;
   }
   Object value = opt.get();
   JsonSerializer<Object> ser = _valueSerializer;
   if (ser == null) {
     ser = _findCachedSerializer(provider, value.getClass());
   }
   if (_valueTypeSerializer != null) {
     ser.serializeWithType(value, gen, provider, _valueTypeSerializer);
   } else {
     ser.serialize(value, gen, provider);
   }
 }
  /**
   * General-purpose serialization for contents, where we do not necessarily know the value
   * serialization, but we do know that no value suppression is needed (which simplifies processing
   * a bit)
   */
  public void serializeFields(Map<?, ?> value, JsonGenerator gen, SerializerProvider provider)
      throws IOException {
    // If value type needs polymorphic type handling, some more work needed:
    if (_valueTypeSerializer != null) {
      serializeTypedFields(value, gen, provider, null);
      return;
    }
    final JsonSerializer<Object> keySerializer = _keySerializer;
    final Set<String> ignored = _ignoredEntries;
    Object keyElem = null;

    try {
      for (Map.Entry<?, ?> entry : value.entrySet()) {
        Object valueElem = entry.getValue();
        // First, serialize key
        keyElem = entry.getKey();
        if (keyElem == null) {
          provider.findNullKeySerializer(_keyType, _property).serialize(null, gen, provider);
        } else {
          // One twist: is entry ignorable? If so, skip
          if ((ignored != null) && ignored.contains(keyElem)) {
            continue;
          }
          keySerializer.serialize(keyElem, gen, provider);
        }
        // And then value
        if (valueElem == null) {
          provider.defaultSerializeNull(gen);
          continue;
        }
        JsonSerializer<Object> serializer = _valueSerializer;
        if (serializer == null) {
          serializer = _findSerializer(provider, valueElem);
        }
        serializer.serialize(valueElem, gen, provider);
      }
    } catch (Exception e) { // Add reference information
      wrapAndThrow(provider, e, value, String.valueOf(keyElem));
    }
  }
Example #14
0
  /**
   * Method called to serialize fields, when the value type is statically known, so that value
   * serializer is passed and does not need to be fetched from provider.
   */
  protected void serializeFieldsUsing(
      Map<?, ?> value, JsonGenerator jgen, SerializerProvider provider, JsonSerializer<Object> ser)
      throws IOException, JsonGenerationException {
    final JsonSerializer<Object> keySerializer = _keySerializer;
    final HashSet<String> ignored = _ignoredEntries;
    final TypeSerializer typeSer = _valueTypeSerializer;
    final boolean skipNulls = !provider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES);

    for (Map.Entry<?, ?> entry : value.entrySet()) {
      Object valueElem = entry.getValue();
      Object keyElem = entry.getKey();
      if (keyElem == null) {
        provider.findNullKeySerializer(_keyType, _property).serialize(null, jgen, provider);
      } else {
        // [JACKSON-314] also may need to skip entries with null values
        if (skipNulls && valueElem == null) continue;
        if (ignored != null && ignored.contains(keyElem)) continue;
        keySerializer.serialize(keyElem, jgen, provider);
      }
      if (valueElem == null) {
        provider.defaultSerializeNull(jgen);
      } else {
        try {
          if (typeSer == null) {
            ser.serialize(valueElem, jgen, provider);
          } else {
            ser.serializeWithType(valueElem, jgen, provider, typeSer);
          }
        } catch (Exception e) {
          // [JACKSON-55] Need to add reference information
          String keyDesc = "" + keyElem;
          wrapAndThrow(provider, e, value, keyDesc);
        }
      }
    }
  }
 public void serializeContents(
     Object[] paramArrayOfObject,
     JsonGenerator paramJsonGenerator,
     SerializerProvider paramSerializerProvider)
     throws IOException {
   int k = paramArrayOfObject.length;
   if (k == 0) {
     return;
   }
   if (this._elementSerializer != null) {
     serializeContentsUsing(
         paramArrayOfObject, paramJsonGenerator, paramSerializerProvider, this._elementSerializer);
     return;
   }
   if (this._valueTypeSerializer != null) {
     serializeTypedContents(paramArrayOfObject, paramJsonGenerator, paramSerializerProvider);
     return;
   }
   int j = 0;
   int i = 0;
   Object localObject1 = null;
   for (; ; ) {
     try {
       localPropertySerializerMap = this._dynamicSerializers;
       if (i >= k) {
         break;
       }
       localObject2 = paramArrayOfObject[i];
       if (localObject2 == null) {
         localObject1 = localObject2;
         j = i;
         paramSerializerProvider.defaultSerializeNull(paramJsonGenerator);
         break label268;
       }
       localObject1 = localObject2;
       j = i;
       localClass = localObject2.getClass();
       localObject1 = localObject2;
       j = i;
       JsonSerializer localJsonSerializer2 = localPropertySerializerMap.serializerFor(localClass);
       localJsonSerializer1 = localJsonSerializer2;
       if (localJsonSerializer2 == null) {
         localObject1 = localObject2;
         j = i;
         if (!this._elementType.hasGenericTypes()) {
           continue;
         }
         localObject1 = localObject2;
         j = i;
         localJsonSerializer1 =
             _findAndAddDynamic(
                 localPropertySerializerMap,
                 paramSerializerProvider.constructSpecializedType(this._elementType, localClass),
                 paramSerializerProvider);
       }
     } catch (IOException paramArrayOfObject) {
       PropertySerializerMap localPropertySerializerMap;
       Object localObject2;
       Class localClass;
       throw paramArrayOfObject;
       localObject1 = localObject2;
       j = i;
       JsonSerializer localJsonSerializer1 =
           _findAndAddDynamic(localPropertySerializerMap, localClass, paramSerializerProvider);
       continue;
     } catch (Exception paramArrayOfObject) {
       if ((!(paramArrayOfObject instanceof InvocationTargetException))
           || (paramArrayOfObject.getCause() == null)) {
         continue;
       }
       paramArrayOfObject = paramArrayOfObject.getCause();
       continue;
       if (!(paramArrayOfObject instanceof Error)) {
         continue;
       }
       throw ((Error) paramArrayOfObject);
       throw JsonMappingException.wrapWithPath(paramArrayOfObject, localObject1, j);
     }
     localObject1 = localObject2;
     j = i;
     localJsonSerializer1.serialize(localObject2, paramJsonGenerator, paramSerializerProvider);
     label268:
     i += 1;
   }
 }
 protected void serializeContents(
     EnumMap<? extends Enum<?>, ?> paramEnumMap,
     JsonGenerator paramJsonGenerator,
     SerializerProvider paramSerializerProvider)
     throws IOException, JsonGenerationException {
   if (this._valueSerializer != null) {
     serializeContentsUsing(
         paramEnumMap, paramJsonGenerator, paramSerializerProvider, this._valueSerializer);
   }
   label70:
   label207:
   label291:
   label303:
   for (; ; ) {
     return;
     Object localObject1 = null;
     Object localObject4 = null;
     Object localObject2 = this._keyEnums;
     int i;
     boolean bool;
     TypeSerializer localTypeSerializer;
     Iterator localIterator;
     if (!paramSerializerProvider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES)) {
       i = 1;
       bool = paramSerializerProvider.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
       localTypeSerializer = this._valueTypeSerializer;
       localIterator = paramEnumMap.entrySet().iterator();
     }
     for (; ; ) {
       if (!localIterator.hasNext()) {
         break label303;
       }
       Map.Entry localEntry = (Map.Entry) localIterator.next();
       Object localObject6 = localEntry.getValue();
       if ((i == 0) || (localObject6 != null)) {
         Object localObject5 = (Enum) localEntry.getKey();
         if (bool) {
           paramJsonGenerator.writeFieldName(((Enum) localObject5).toString());
         }
         Object localObject3;
         for (; ; ) {
           if (localObject6 != null) {
             break label207;
           }
           paramSerializerProvider.defaultSerializeNull(paramJsonGenerator);
           break label70;
           i = 0;
           break;
           localObject3 = localObject2;
           if (localObject2 == null) {
             localObject3 =
                 ((EnumSerializer)
                         paramSerializerProvider.findValueSerializer(
                             ((Enum) localObject5).getDeclaringClass(), this._property))
                     .getEnumValues();
           }
           paramJsonGenerator.writeFieldName(
               ((EnumValues) localObject3).serializedValueFor((Enum) localObject5));
           localObject2 = localObject3;
         }
         localObject5 = localObject6.getClass();
         if (localObject5 == localObject4) {
           localObject3 = localObject1;
         }
         JsonSerializer localJsonSerializer;
         for (; ; ) {
           if (localTypeSerializer != null) {
             break label291;
           }
           try {
             ((JsonSerializer) localObject3)
                 .serialize(localObject6, paramJsonGenerator, paramSerializerProvider);
           } catch (Exception localException) {
             wrapAndThrow(
                 paramSerializerProvider,
                 localException,
                 paramEnumMap,
                 ((Enum) localEntry.getKey()).name());
           }
           break;
           localJsonSerializer =
               paramSerializerProvider.findValueSerializer((Class) localObject5, this._property);
           localObject1 = localJsonSerializer;
           localObject4 = localObject5;
         }
         localJsonSerializer.serializeWithType(
             localObject6, paramJsonGenerator, paramSerializerProvider, localTypeSerializer);
       }
     }
   }
 }
 protected void serializeContentsUsing(
     EnumMap<? extends Enum<?>, ?> paramEnumMap,
     JsonGenerator paramJsonGenerator,
     SerializerProvider paramSerializerProvider,
     JsonSerializer<Object> paramJsonSerializer)
     throws IOException, JsonGenerationException {
   Object localObject1 = this._keyEnums;
   int i;
   boolean bool;
   TypeSerializer localTypeSerializer;
   Iterator localIterator;
   if (!paramSerializerProvider.isEnabled(SerializationFeature.WRITE_NULL_MAP_VALUES)) {
     i = 1;
     bool = paramSerializerProvider.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
     localTypeSerializer = this._valueTypeSerializer;
     localIterator = paramEnumMap.entrySet().iterator();
   }
   for (; ; ) {
     label45:
     if (!localIterator.hasNext()) {
       return;
     }
     Map.Entry localEntry = (Map.Entry) localIterator.next();
     Object localObject3 = localEntry.getValue();
     if ((i == 0) || (localObject3 != null)) {
       Enum localEnum = (Enum) localEntry.getKey();
       if (bool) {
         paramJsonGenerator.writeFieldName(localEnum.toString());
       }
       for (; ; ) {
         if (localObject3 != null) {
           break label182;
         }
         paramSerializerProvider.defaultSerializeNull(paramJsonGenerator);
         break label45;
         i = 0;
         break;
         Object localObject2 = localObject1;
         if (localObject1 == null) {
           localObject2 =
               ((EnumSerializer)
                       paramSerializerProvider.findValueSerializer(
                           localEnum.getDeclaringClass(), this._property))
                   .getEnumValues();
         }
         paramJsonGenerator.writeFieldName(
             ((EnumValues) localObject2).serializedValueFor(localEnum));
         localObject1 = localObject2;
       }
       label182:
       if (localTypeSerializer == null) {
         try {
           paramJsonSerializer.serialize(
               localObject3, paramJsonGenerator, paramSerializerProvider);
         } catch (Exception localException) {
           wrapAndThrow(
               paramSerializerProvider,
               localException,
               paramEnumMap,
               ((Enum) localEntry.getKey()).name());
         }
       } else {
         paramJsonSerializer.serializeWithType(
             localObject3, paramJsonGenerator, paramSerializerProvider, localTypeSerializer);
       }
     }
   }
 }