caravan-protobuf/src/main/java/com/ctrip/soa/caravan/protobuf/v2/customization/map/CustomCollectionDeserializer.java
/**
   * Method called to finalize setup of this deserializer,
   * when it is known for which property deserializer is needed
   * for.
   */
Method called to finalize setup of this deserializer,
when it is known for which property deserializer is needed
for.
Method called to finalize setup of this deserializer when it is known for which property deserializer is needed for .
@Override
  public CustomCollectionDeserializer createContextual(DeserializationContext ctxt,
      BeanProperty property) throws JsonMappingException {
    MapType mapType = (MapType) property.getType();
    JsonDeserializer<Object> delegateDeser = null;
    if (_valueInstantiator != null) {
      if (_valueInstantiator.canCreateUsingDelegate()) {
        JavaType delegateType = _valueInstantiator.getDelegateType(ctxt.getConfig());
        if (delegateType == null) {
          ctxt.reportBadDefinition(_containerType, String.format(
              "Invalid delegate-creator definition for %s: value instantiator (%s) returned true for 'canCreateUsingDelegate()', but null for 'getDelegateType()'",
              _containerType,
              _valueInstantiator.getClass().getName()));
        }
        delegateDeser = findDeserializer(ctxt, delegateType, property);
      } else if (_valueInstantiator.canCreateUsingArrayDelegate()) {
        JavaType delegateType = _valueInstantiator.getArrayDelegateType(ctxt.getConfig());
        if (delegateType == null) {
          ctxt.reportBadDefinition(_containerType, String.format(
              "Invalid delegate-creator definition for %s: value instantiator (%s) returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'",
              _containerType,
              _valueInstantiator.getClass().getName()));
        }
        delegateDeser = findDeserializer(ctxt, delegateType, property);
      }
    }
    Boolean unwrapSingle = findFormatFeature(ctxt, property, Collection.class,
        JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
    JsonDeserializer<?> valueDeser = _valueDeserializer;
    valueDeser = findConvertingContentDeserializer(ctxt, property, valueDeser);
    final JavaType vt = SimpleType.constructUnsafe(DynamicClassFactory.INSTANCE.fetchOrCreatePairClass(mapType));
    if (valueDeser == null) {
      valueDeser = ctxt.findContextualValueDeserializer(vt, property);
    } else { 
      valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
    }
    TypeDeserializer valueTypeDeser = _valueTypeDeserializer;
    if (valueTypeDeser != null) {
      valueTypeDeser = valueTypeDeser.forProperty(property);
    }
    NullValueProvider nuller = findContentNullProvider(ctxt, property, valueDeser);
    if ((unwrapSingle != _unwrapSingle)
        || (nuller != _nullProvider)
        || (delegateDeser != _delegateDeserializer)
        || (valueDeser != _valueDeserializer)
        || (valueTypeDeser != _valueTypeDeserializer)
        ) {
      return withResolved(vt, delegateDeser, valueDeser, valueTypeDeser,
          nuller, unwrapSingle);
    }
    return this;
  }
@ Override public CustomCollectionDeserializer createContextual ( DeserializationContext ctxt , BeanProperty property ) throws JsonMappingException { MapType mapType = ( MapType ) property . getType ( ) ; JsonDeserializer < Object > delegateDeser = null ; if ( _valueInstantiator != null ) { if ( _valueInstantiator . canCreateUsingDelegate ( ) ) { JavaType delegateType = _valueInstantiator . getDelegateType ( ctxt . getConfig ( ) ) ; if ( delegateType == null ) { ctxt . reportBadDefinition ( _containerType , String . format ( "Invalid delegate-creator definition for %s: value instantiator (%s) returned true for 'canCreateUsingDelegate()', but null for 'getDelegateType()'" , _containerType , _valueInstantiator . getClass ( ) . getName ( ) ) ) ; } delegateDeser = findDeserializer ( ctxt , delegateType , property ) ; } else if ( _valueInstantiator . canCreateUsingArrayDelegate ( ) ) { JavaType delegateType = _valueInstantiator . getArrayDelegateType ( ctxt . getConfig ( ) ) ; if ( delegateType == null ) { ctxt . reportBadDefinition ( _containerType , String . format ( "Invalid delegate-creator definition for %s: value instantiator (%s) returned true for 'canCreateUsingArrayDelegate()', but null for 'getArrayDelegateType()'" , _containerType , _valueInstantiator . getClass ( ) . getName ( ) ) ) ; } delegateDeser = findDeserializer ( ctxt , delegateType , property ) ; } } Boolean unwrapSingle = findFormatFeature ( ctxt , property , Collection . class , JsonFormat . Feature . ACCEPT_SINGLE_VALUE_AS_ARRAY ) ; JsonDeserializer < ? > valueDeser = _valueDeserializer ; valueDeser = findConvertingContentDeserializer ( ctxt , property , valueDeser ) ; final JavaType vt = SimpleType . constructUnsafe ( DynamicClassFactory . INSTANCE . fetchOrCreatePairClass ( mapType ) ) ; if ( valueDeser == null ) { valueDeser = ctxt . findContextualValueDeserializer ( vt , property ) ; } else { valueDeser = ctxt . handleSecondaryContextualization ( valueDeser , property , vt ) ; } TypeDeserializer valueTypeDeser = _valueTypeDeserializer ; if ( valueTypeDeser != null ) { valueTypeDeser = valueTypeDeser . forProperty ( property ) ; } NullValueProvider nuller = findContentNullProvider ( ctxt , property , valueDeser ) ; if ( ( unwrapSingle != _unwrapSingle ) || ( nuller != _nullProvider ) || ( delegateDeser != _delegateDeserializer ) || ( valueDeser != _valueDeserializer ) || ( valueTypeDeser != _valueTypeDeserializer ) ) { return withResolved ( vt , delegateDeser , valueDeser , valueTypeDeser , nuller , unwrapSingle ) ; } return this ; }
Method called to finalize setup of this deserializer,
 when it is known for which property deserializer is needed
 for.
Method called to finalize setup of this deserializer when it is known for which property deserializer is needed for .
// May need to resolve types for delegate-based creators: // [databind#1043]: allow per-property allow-wrapping of single overrides: // 11-Dec-2015, tatu: Should we pass basic `Collection.class`, or more refined? Mostly //   comes down to "List vs Collection" I suppose... for now, pass Collection // also, often value deserializer is resolved here: // May have a content converter // if directly assigned, probably not yet contextual, so: // and finally, type deserializer needs context as well