package sh.calaba.org.codehaus.jackson.map.deser; import java.io.IOException; import java.text.DateFormat; import java.text.ParseException; import java.util.*; import sh.calaba.org.codehaus.jackson.JsonParser; import sh.calaba.org.codehaus.jackson.JsonProcessingException; import sh.calaba.org.codehaus.jackson.JsonToken; import sh.calaba.org.codehaus.jackson.map.*; import sh.calaba.org.codehaus.jackson.map.exc.UnrecognizedPropertyException; import sh.calaba.org.codehaus.jackson.map.util.ArrayBuilders; import sh.calaba.org.codehaus.jackson.map.util.ClassUtil; import sh.calaba.org.codehaus.jackson.map.util.LinkedNode; import sh.calaba.org.codehaus.jackson.map.util.ObjectBuffer; import sh.calaba.org.codehaus.jackson.type.JavaType; /** * Default implementation of {@link DeserializationContext}. */ public class StdDeserializationContext extends DeserializationContext { /** * Let's limit length of error messages, for cases where underlying data * may be very large -- no point in spamming logs with megs of meaningless * data. */ final static int MAX_ERROR_STR_LEN = 500; // // // Configuration /** * Currently active parser used for deserialization. * May be different from the outermost parser * when content is buffered. */ protected JsonParser _parser; /** * @since 1.5 */ protected final DeserializerProvider _deserProvider; /** * @since 1.9 */ protected final InjectableValues _injectableValues; // // // Helper object recycling protected ArrayBuilders _arrayBuilders; protected ObjectBuffer _objectBuffer; protected DateFormat _dateFormat; /* /********************************************************** /* Life-cycle /********************************************************** */ public StdDeserializationContext(DeserializationConfig config, JsonParser jp, DeserializerProvider prov, InjectableValues injectableValues) { super(config); _parser = jp; _deserProvider = prov; _injectableValues = injectableValues; } /* /********************************************************** /* Public API, accessors /********************************************************** */ @Override public DeserializerProvider getDeserializerProvider() { return _deserProvider; } /** * Method for accessing the currently active parser. * May be different from the outermost parser * when content is buffered. *
* Use of this method is discouraged: if code has direct access
* to the active parser, that should be used instead.
*/
@Override
public JsonParser getParser() { return _parser; }
@Override
public Object findInjectableValue(Object valueId,
BeanProperty forProperty, Object beanInstance)
{
if (_injectableValues == null) {
throw new IllegalStateException("No 'injectableValues' configured, can not inject value with id ["+valueId+"]");
}
return _injectableValues.findInjectableValue(valueId, this, forProperty, beanInstance);
}
/*
/**********************************************************
/* Public API, helper object recycling
/**********************************************************
*/
@Override
public final ObjectBuffer leaseObjectBuffer()
{
ObjectBuffer buf = _objectBuffer;
if (buf == null) {
buf = new ObjectBuffer();
} else {
_objectBuffer = null;
}
return buf;
}
@Override
public final void returnObjectBuffer(ObjectBuffer buf)
{
/* Already have a reusable buffer? Let's retain bigger one
* (or if equal, favor newer one, shorter life-cycle)
*/
if (_objectBuffer == null
|| buf.initialCapacity() >= _objectBuffer.initialCapacity()) {
_objectBuffer = buf;
}
}
@Override
public final ArrayBuilders getArrayBuilders()
{
if (_arrayBuilders == null) {
_arrayBuilders = new ArrayBuilders();
}
return _arrayBuilders;
}
/*
/**********************************************************
/* Parsing methods that may use reusable/recyclable objects
/**********************************************************
*/
@Override
public Date parseDate(String dateStr)
throws IllegalArgumentException
{
try {
return getDateFormat().parse(dateStr);
} catch (ParseException pex) {
throw new IllegalArgumentException(pex.getMessage());
}
}
@Override
public Calendar constructCalendar(Date d)
{
/* 08-Jan-2008, tatu: not optimal, but should work for the
* most part; let's revise as needed.
*/
Calendar c = Calendar.getInstance();
c.setTime(d);
return c;
}
/*
/**********************************************************
/* Public API, problem handling, reporting
/**********************************************************
*/
/**
* Method deserializers can call to inform configured {@link DeserializationProblemHandler}s
* of an unrecognized property.
*
* @since 1.5
*/
@Override
public boolean handleUnknownProperty(JsonParser jp, JsonDeserializer> deser, Object instanceOrClass, String propName)
throws IOException, JsonProcessingException
{
LinkedNode