public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property)
     throws JsonMappingException {
   JsonSerializer<?> ser = null;
   if (property != null) {
     AnnotatedMember m = property.getMember();
     if (m != null) {
       Object serDef = provider.getAnnotationIntrospector().findContentSerializer(m);
       if (serDef != null) {
         ser = provider.serializerInstance(m, serDef);
       }
     }
   }
   if (ser == null) {
     ser = this._elementSerializer;
   }
   ser = findConvertingContentSerializer(provider, property, ser);
   if (ser == null) {
     ser = provider.findValueSerializer(String.class, property);
   } else {
     ser = provider.handleSecondaryContextualization(ser, property);
   }
   if (isDefaultSerializer(ser)) {
     ser = null;
   }
   return ser == this._elementSerializer ? this : new StringArraySerializer(this, property, ser);
 }
 public JsonSerializer<?> createContextual(
     SerializerProvider paramSerializerProvider, BeanProperty paramBeanProperty)
     throws JsonMappingException {
   Object localObject2 = null;
   Object localObject1 = localObject2;
   if (paramBeanProperty != null) {
     AnnotatedMember localAnnotatedMember = paramBeanProperty.getMember();
     localObject1 = localObject2;
     if (localAnnotatedMember != null) {
       Object localObject3 =
           paramSerializerProvider
               .getAnnotationIntrospector()
               .findContentSerializer(localAnnotatedMember);
       localObject1 = localObject2;
       if (localObject3 != null) {
         localObject1 =
             paramSerializerProvider.serializerInstance(localAnnotatedMember, localObject3);
       }
     }
   }
   localObject2 = localObject1;
   if (localObject1 == null) {
     localObject2 = this._valueSerializer;
   }
   localObject1 =
       findConvertingContentSerializer(
           paramSerializerProvider, paramBeanProperty, (JsonSerializer) localObject2);
   if (localObject1 == null) {
     if (!this._staticTyping) {
       break label111;
     }
     paramSerializerProvider =
         withValueSerializer(
             paramBeanProperty,
             paramSerializerProvider.findValueSerializer(this._valueType, paramBeanProperty));
   }
   label111:
   do {
     return paramSerializerProvider;
     localObject1 =
         paramSerializerProvider.handleSecondaryContextualization(
             (JsonSerializer) localObject1, paramBeanProperty);
     paramSerializerProvider = this;
   } while (localObject1 == this._valueSerializer);
   return withValueSerializer(paramBeanProperty, (JsonSerializer) localObject1);
 }
 @Override
 public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property)
     throws JsonMappingException {
   /* 29-Sep-2012, tatu: Actually, we need to do much more contextual
    *    checking here since we finally know for sure the property,
    *    and it may have overrides
    */
   JsonSerializer<?> ser = null;
   // First: if we have a property, may have property-annotation overrides
   if (property != null) {
     AnnotatedMember m = property.getMember();
     if (m != null) {
       Object serDef = provider.getAnnotationIntrospector().findContentSerializer(m);
       if (serDef != null) {
         ser = provider.serializerInstance(m, serDef);
       }
     }
   }
   if (ser == null) {
     ser = _serializer;
   }
   // #124: May have a content converter
   ser = findConvertingContentSerializer(provider, property, ser);
   if (ser == null) {
     ser = provider.findValueSerializer(String.class, property);
   } else {
     ser = provider.handleSecondaryContextualization(ser, property);
   }
   // Optimization: default serializer just writes String, so we can avoid a call:
   if (isDefaultSerializer(ser)) {
     ser = null;
   }
   // note: will never have TypeSerializer, because Strings are "natural" type
   if (ser == _serializer) {
     return this;
   }
   return new IndexedStringListSerializer(ser);
 }
 public JsonSerializer<?> createContextual(
     SerializerProvider paramSerializerProvider, BeanProperty paramBeanProperty)
     throws JsonMappingException {
   Object localObject1 = this._valueTypeSerializer;
   Object localObject3 = localObject1;
   if (localObject1 != null) {
     localObject3 = ((TypeSerializer) localObject1).forProperty(paramBeanProperty);
   }
   Object localObject2 = null;
   JsonFormat.Value localValue = null;
   Object localObject5 = null;
   Object localObject4 = localObject5;
   if (paramBeanProperty != null) {
     localObject4 = paramBeanProperty.getMember();
     localObject2 = paramSerializerProvider.getAnnotationIntrospector();
     localObject1 = localValue;
     if (localObject4 != null) {
       Object localObject6 =
           ((AnnotationIntrospector) localObject2).findContentSerializer((Annotated) localObject4);
       localObject1 = localValue;
       if (localObject6 != null) {
         localObject1 =
             paramSerializerProvider.serializerInstance((Annotated) localObject4, localObject6);
       }
     }
     localValue = paramBeanProperty.findFormatOverrides((AnnotationIntrospector) localObject2);
     localObject2 = localObject1;
     localObject4 = localObject5;
     if (localValue != null) {
       localObject4 = localValue.getFeature(JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED);
       localObject2 = localObject1;
     }
   }
   localObject1 = localObject2;
   if (localObject2 == null) {
     localObject1 = this._elementSerializer;
   }
   localObject2 =
       findConvertingContentSerializer(
           paramSerializerProvider, paramBeanProperty, (JsonSerializer) localObject1);
   if (localObject2 == null) {
     localObject1 = localObject2;
     if (this._elementType != null) {
       if (!this._staticTyping) {
         localObject1 = localObject2;
         if (!hasContentTypeAnnotation(paramSerializerProvider, paramBeanProperty)) {
           break label185;
         }
       }
     }
   }
   for (localObject1 =
           paramSerializerProvider.findValueSerializer(this._elementType, paramBeanProperty);
       ;
       localObject1 =
           paramSerializerProvider.handleSecondaryContextualization(
               (JsonSerializer) localObject2, paramBeanProperty)) {
     label185:
     return withResolved(
         paramBeanProperty,
         (TypeSerializer) localObject3,
         (JsonSerializer) localObject1,
         (Boolean) localObject4);
   }
 }
Пример #5
0
  @Override
  public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property)
      throws JsonMappingException {
    JsonSerializer<?> ser = null;
    JsonSerializer<?> keySer = null;
    final AnnotationIntrospector intr = provider.getAnnotationIntrospector();
    final AnnotatedMember propertyAcc = (property == null) ? null : property.getMember();

    // First: if we have a property, may have property-annotation overrides
    if ((propertyAcc != null) && (intr != null)) {
      Object serDef = intr.findKeySerializer(propertyAcc);
      if (serDef != null) {
        keySer = provider.serializerInstance(propertyAcc, serDef);
      }
      serDef = intr.findContentSerializer(propertyAcc);
      if (serDef != null) {
        ser = provider.serializerInstance(propertyAcc, serDef);
      }
    }
    if (ser == null) {
      ser = _valueSerializer;
    }
    // [databind#124]: May have a content converter
    ser = findContextualConvertingSerializer(provider, property, ser);
    if (ser == null) {
      // 30-Sep-2012, tatu: One more thing -- if explicit content type is annotated,
      //   we can consider it a static case as well.
      // 20-Aug-2013, tatu: Need to avoid trying to access serializer for java.lang.Object tho
      if (_valueTypeIsStatic && !_valueType.isJavaLangObject()) {
        ser = provider.findValueSerializer(_valueType, property);
      }
    }
    if (keySer == null) {
      keySer = _keySerializer;
    }
    if (keySer == null) {
      keySer = provider.findKeySerializer(_keyType, property);
    } else {
      keySer = provider.handleSecondaryContextualization(keySer, property);
    }
    Set<String> ignored = _ignoredEntries;
    boolean sortKeys = false;
    if ((intr != null) && (propertyAcc != null)) {
      JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(propertyAcc);
      if (ignorals != null) {
        Set<String> newIgnored = ignorals.findIgnoredForSerialization();
        if ((newIgnored != null) && !newIgnored.isEmpty()) {
          ignored = (ignored == null) ? new HashSet<String>() : new HashSet<String>(ignored);
          for (String str : newIgnored) {
            ignored.add(str);
          }
        }
      }
      Boolean b = intr.findSerializationSortAlphabetically(propertyAcc);
      sortKeys = (b != null) && b.booleanValue();
    }
    JsonFormat.Value format = findFormatOverrides(provider, property, Map.class);
    if (format != null) {
      Boolean B = format.getFeature(JsonFormat.Feature.WRITE_SORTED_MAP_ENTRIES);
      if (B != null) {
        sortKeys = B.booleanValue();
      }
    }
    MapSerializer mser = withResolved(property, keySer, ser, ignored, sortKeys);

    // [databind#307]: allow filtering
    if (property != null) {
      AnnotatedMember m = property.getMember();
      if (m != null) {
        Object filterId = intr.findFilterId(m);
        if (filterId != null) {
          mser = mser.withFilterId(filterId);
        }
      }
      JsonInclude.Value inclV = property.findPropertyInclusion(provider.getConfig(), null);
      if (inclV != null) {
        JsonInclude.Include incl = inclV.getContentInclusion();

        if (incl != JsonInclude.Include.USE_DEFAULTS) {
          Object valueToSuppress;
          boolean suppressNulls;
          switch (incl) {
            case NON_DEFAULT:
              valueToSuppress = BeanUtil.getDefaultValue(_valueType);
              suppressNulls = true;
              if (valueToSuppress != null) {
                if (valueToSuppress.getClass().isArray()) {
                  valueToSuppress = ArrayBuilders.getArrayComparator(valueToSuppress);
                }
              }
              break;
            case NON_ABSENT:
              suppressNulls = true;
              valueToSuppress = _valueType.isReferenceType() ? MARKER_FOR_EMPTY : null;
              break;
            case NON_EMPTY:
              suppressNulls = true;
              valueToSuppress = MARKER_FOR_EMPTY;
              break;
            case CUSTOM:
              valueToSuppress = provider.includeFilterInstance(null, inclV.getContentFilter());
              if (valueToSuppress == null) { // is this legal?
                suppressNulls = true;
              } else {
                suppressNulls = provider.includeFilterSuppressNulls(valueToSuppress);
              }
              break;
            case NON_NULL:
              valueToSuppress = null;
              suppressNulls = true;
              break;
            case ALWAYS: // default
            default:
              valueToSuppress = null;
              // 30-Sep-2016, tatu: Should not need to check global flags here,
              //   if inclusion forced to be ALWAYS
              suppressNulls = false;
              break;
          }
          mser = mser.withContentInclusion(valueToSuppress, suppressNulls);
        }
      }
    }
    return mser;
  }