@Override
 public Map<Object, Object> deserialize(
     JsonParser jp, DeserializationContext ctxt, Map<Object, Object> result)
     throws IOException, JsonProcessingException {
   // Ok: must point to START_OBJECT or FIELD_NAME
   JsonToken t = jp.getCurrentToken();
   if (t != JsonToken.START_OBJECT && t != JsonToken.FIELD_NAME) {
     throw ctxt.mappingException(getMapClass());
   }
   _readAndBind(jp, ctxt, result);
   return result;
 }
  public Object deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException, JsonProcessingException {
    // Ok: must point to START_ARRAY
    if (jp.getCurrentToken() != JsonToken.START_ARRAY) {
      /* 04-Oct-2009, tatu: One exception; byte arrays are generally
       *   serialized as base64, so that should be handled
       */
      if (jp.getCurrentToken() == JsonToken.VALUE_STRING && _elementClass == Byte.class) {
        return deserializeFromBase64(jp, ctxt);
      }
      throw ctxt.mappingException(_arrayType.getRawClass());
    }

    final ObjectBuffer buffer = ctxt.leaseObjectBuffer();
    Object[] chunk = buffer.resetAndStart();
    int ix = 0;
    JsonToken t;
    final TypeDeserializer typeDeser = _elementTypeDeserializer;

    while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
      // Note: must handle null explicitly here; value deserializers won't
      Object value;

      if (t == JsonToken.VALUE_NULL) {
        value = null;
      } else if (typeDeser == null) {
        value = _elementDeserializer.deserialize(jp, ctxt);
      } else {
        value = _elementDeserializer.deserializeWithType(jp, ctxt, typeDeser);
      }
      if (ix >= chunk.length) {
        chunk = buffer.appendCompletedChunk(chunk);
        ix = 0;
      }
      chunk[ix++] = value;
    }

    Object[] result;

    if (_untyped) {
      result = buffer.completeAndClearBuffer(chunk, ix);
    } else {
      result = buffer.completeAndClearBuffer(chunk, ix, _elementClass);
    }
    ctxt.returnObjectBuffer(buffer);
    return result;
  }
Example #3
0
 @SuppressWarnings("unchecked")
 @Override
 public T deserialize(JsonParser jp, DeserializationContext ctxt)
     throws IOException, JsonProcessingException {
   JsonToken t = jp.getCurrentToken();
   if (t == JsonToken.VALUE_NUMBER_INT) {
     return (T) new DateTime(jp.getLongValue(), DateTimeZone.UTC);
   }
   if (t == JsonToken.VALUE_STRING) {
     String str = jp.getText().trim();
     if (str.length() == 0) { // [JACKSON-360]
       return null;
     }
     return (T) new DateTime(str, DateTimeZone.UTC);
   }
   throw ctxt.mappingException(getValueClass());
 }
 @Override
 public Map<Object, Object> deserialize(JsonParser jp, DeserializationContext ctxt)
     throws IOException, JsonProcessingException {
   // Ok: must point to START_OBJECT, or FIELD_NAME
   JsonToken t = jp.getCurrentToken();
   if (t != JsonToken.START_OBJECT && t != JsonToken.FIELD_NAME) {
     throw ctxt.mappingException(getMapClass());
   }
   if (_propertyBasedCreator != null) {
     return _deserializeUsingCreator(jp, ctxt);
   }
   Map<Object, Object> result;
   if (_defaultCtor == null) {
     throw ctxt.instantiationException(getMapClass(), "No default constructor found");
   }
   try {
     result = _defaultCtor.newInstance();
   } catch (Exception e) {
     throw ctxt.instantiationException(getMapClass(), e);
   }
   _readAndBind(jp, ctxt, result);
   return result;
 }