caravan-protobuf/src/main/java/com/ctrip/soa/caravan/protobuf/v2/customization/map/CustomCollectionDeserializer.java
/**
   * Helper method called when current token is no START_ARRAY. Will either
   * throw an exception, or try to handle value as if member of implicit
   * array, depending on configuration.
   */
Helper method called when current token is no START_ARRAY. Will either
throw an exception, or try to handle value as if member of implicit
array, depending on configuration.
Helper method called when current token is no START_ARRAY . Will either throw an exception or try to handle value as if member of implicit array depending on configuration .
@SuppressWarnings("unchecked")
  protected final Collection<Object> handleNonArray(JsonParser p, DeserializationContext ctxt,
      Collection<Object> result)
      throws IOException {
    boolean canWrap = (_unwrapSingle == Boolean.TRUE) ||
        ((_unwrapSingle == null) &&
            ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY));
    if (!canWrap) {
      return (Collection<Object>) ctxt.handleUnexpectedToken(_containerType.getRawClass(), p);
    }
    JsonDeserializer<Object> valueDes = _valueDeserializer;
    final TypeDeserializer typeDeser = _valueTypeDeserializer;
    JsonToken t = p.getCurrentToken();
    Object value;
    try {
      if (t == JsonToken.VALUE_NULL) {
        if (_skipNullValues) {
          return result;
        }
        value = _nullProvider.getNullValue(ctxt);
      } else if (typeDeser == null) {
        value = valueDes.deserialize(p, ctxt);
      } else {
        value = valueDes.deserializeWithType(p, ctxt, typeDeser);
      }
    } catch (Exception e) {
      throw JsonMappingException.wrapWithPath(e, Object.class, result.size());
    }
    result.add(value);
    return result;
  }
@ SuppressWarnings ( "unchecked" ) protected final Collection < Object > handleNonArray ( JsonParser p , DeserializationContext ctxt , Collection < Object > result ) throws IOException { boolean canWrap = ( _unwrapSingle == Boolean . TRUE ) || ( ( _unwrapSingle == null ) && ctxt . isEnabled ( DeserializationFeature . ACCEPT_SINGLE_VALUE_AS_ARRAY ) ) ; if ( ! canWrap ) { return ( Collection < Object > ) ctxt . handleUnexpectedToken ( _containerType . getRawClass ( ) , p ) ; } JsonDeserializer < Object > valueDes = _valueDeserializer ; final TypeDeserializer typeDeser = _valueTypeDeserializer ; JsonToken t = p . getCurrentToken ( ) ; Object value ; try { if ( t == JsonToken . VALUE_NULL ) { if ( _skipNullValues ) { return result ; } value = _nullProvider . getNullValue ( ctxt ) ; } else if ( typeDeser == null ) { value = valueDes . deserialize ( p , ctxt ) ; } else { value = valueDes . deserializeWithType ( p , ctxt , typeDeser ) ; } } catch ( Exception e ) { throw JsonMappingException . wrapWithPath ( e , Object . class , result . size ( ) ) ; } result . add ( value ) ; return result ; }
Helper method called when current token is no START_ARRAY.
Helper method called when current token is no START_ARRAY .
// Implicit arrays from single values? // 03-Feb-2017, tatu: Hmmh. I wonder... let's try skipping here, too // note: pass Object.class, not Object[].class, as we need element type for error info