if (!jp.isExpectedStartArrayToken()) {
// punt to super method for edge case handling, we won't need to report any indexes anyway
return super.deserialize(jp, ctxt);
}
final ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] chunk = buffer.resetAndStart();
int ix = 0;
JsonToken t;
final TypeDeserializer typeDeser = _elementTypeDeserializer;
try {
while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
if (ix >= chunk.length) {
chunk = buffer.appendCompletedChunk(chunk);
ix = 0;
}
// Note: must handle null explicitly here; value deserializers won't
Object value;
if (t == JsonToken.VALUE_NULL) {
value = _elementDeserializer.getNullValue();
} else if (typeDeser == null) {
value = _elementDeserializer.deserialize(jp, ctxt);
} else {
value = _elementDeserializer.deserializeWithType(jp, ctxt, typeDeser);
}
chunk[ix] = value;
ix++;
}
} catch (Exception e) {
// note: pass Object.class, not Object[].class, as we need element type for error info
// addition: add buffer.bufferedSize() since ix gets periodically reset
// addition: report _elementClass instead of hard-coded Object.class
throw JsonMappingException.wrapWithPath(e, _elementClass, ix + buffer.bufferedSize());
}
Object[] result;
if (_untyped) {
result = buffer.completeAndClearBuffer(chunk, ix);
} else {
result = buffer.completeAndClearBuffer(chunk, ix, _elementClass);
}
ctxt.returnObjectBuffer(buffer);
return result;
}