protected final Object _deserializeWithErrorWrapping(JsonParser p, DeserializationContext ctxt, SettableBeanProperty prop) throws IOException { try { return prop.deserialize(p, ctxt); } catch (Exception e) { wrapAndThrow(e, _beanType.getRawClass(), prop.getName(), ctxt); // never gets here, unless caller declines to throw an exception return null; } }
@Override public void handleResolvedForwardReference(Object id, Object value) throws IOException { if (_bean == null) { _context.reportInputMismatch(_prop, "Cannot resolve ObjectId forward reference using property '%s' (of type %s): Bean not yet resolved", _prop.getName(), _prop.getDeclaringClass().getName()); } _prop.set(_bean, value); } }
/** * Factory method used for building actual instances to be used with POJOS: * resolves deserializers, checks for "null values". * * @since 2.9 */ public static PropertyBasedCreator construct(DeserializationContext ctxt, ValueInstantiator valueInstantiator, SettableBeanProperty[] srcCreatorProps, BeanPropertyMap allProperties) throws JsonMappingException { final int len = srcCreatorProps.length; SettableBeanProperty[] creatorProps = new SettableBeanProperty[len]; for (int i = 0; i < len; ++i) { SettableBeanProperty prop = srcCreatorProps[i]; if (!prop.hasValueDeserializer()) { prop = prop.withValueDeserializer(ctxt.findContextualValueDeserializer(prop.getType(), prop)); } creatorProps[i] = prop; } return new PropertyBasedCreator(ctxt, valueInstantiator, creatorProps, allProperties.isCaseInsensitive(), allProperties.hasAliases()); }
@Override public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object instance) throws IOException { Object oldValue = _accessor.getValue(instance); Object newValue; // 20-Oct-2016, tatu: Couple of possibilities of how to proceed; for // now, default to "normal" handling without merging if (oldValue == null) { newValue = delegate.deserialize(p, ctxt); } else { newValue = delegate.deserializeWith(p, ctxt, oldValue); } if (newValue != oldValue) { // 18-Apr-2017, tatu: Null handling should occur within delegate, which may // set/skip/transform it, or throw an exception. delegate.set(instance, newValue); } }
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); Object builder = null; if (creatorProp != null) { if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) { t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT try { builder = creator.build(ctxt, buffer); } catch (Exception e) { wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt); continue; // never gets here if (builder.getClass() != _beanType.getRawClass()) { return handlePolymorphic(p, ctxt, builder, tokens); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { buffer.bufferProperty(prop, prop.deserialize(p, ctxt)); continue; continue; tokens.writeFieldName(propName); tokens.copyCurrentStructure(p);
return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(p, ctxt)); boolean hasStringCreator = _valueInstantiator.canCreateFromString(); boolean hasDefaultCtor = _valueInstantiator.canCreateUsingDefault(); return ctxt.handleMissingInstantiator(handledType(), getValueInstantiator(), p, "Throwable needs a default contructor, a single-String-arg constructor; or explicit @JsonCreator"); int pendingIx = 0; prop.deserializeAndSet(p, ctxt, throwable); continue; int len = _beanProperties.size(); pending = new Object[len + len]; pending[pendingIx++] = prop.deserialize(p, ctxt); continue; for (int i = 0, len = pendingIx; i < len; i += 2) { prop = (SettableBeanProperty)pending[i]; prop.set(throwable, pending[i+1]); for (int i = 0, len = pendingIx; i < len; i += 2) { SettableBeanProperty prop = (SettableBeanProperty)pending[i]; prop.set(throwable, pending[i+1]);
protected final Object deserializeWithView(JsonParser p, DeserializationContext ctxt, Object bean, Class<?> activeView) throws IOException { JsonToken t = p.getCurrentToken(); for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); // Skip field name: p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { if (!prop.visibleInView(activeView)) { p.skipChildren(); continue; } try { bean = prop.deserializeSetAndReturn(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } handleUnknownVanilla(p, ctxt, bean, propName); } return bean; }
final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; if ((activeView != null) && !creatorProp.visibleInView(activeView)) { p.skipChildren(); continue; if (buffer.assignParameter(creatorProp, creatorProp.deserialize(p, ctxt))) { p.nextToken(); // to move to following FIELD_NAME/END_OBJECT Object builder; if (builder.getClass() != _beanType.getRawClass()) { return handlePolymorphic(p, ctxt, builder, unknown); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { buffer.bufferProperty(prop, prop.deserialize(p, ctxt)); continue; unknown = new TokenBuffer(p, ctxt); unknown.writeFieldName(propName); unknown.copyCurrentStructure(p); if (builder.getClass() != _beanType.getRawClass()) { return handlePolymorphic(null, ctxt, builder, unknown);
/** * Streamlined version that is only used when no "special" * features are enabled. */ private final Object vanillaDeserialize(JsonParser p, DeserializationContext ctxt, JsonToken t) throws IOException { Object bean = _valueInstantiator.createUsingDefault(ctxt); for (; p.getCurrentToken() == JsonToken.FIELD_NAME; p.nextToken()) { String propName = p.getCurrentName(); // Skip field name: p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case try { bean = prop.deserializeSetAndReturn(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } } else { handleUnknownVanilla(p, ctxt, bean, propName); } } return bean; }
throws IOException JsonToken t = p.getCurrentToken(); if (t == JsonToken.START_OBJECT) { t = p.nextToken(); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); SettableBeanProperty prop = _beanProperties.find(propName); p.nextToken(); if (prop != null) { // normal case if (activeView != null && !prop.visibleInView(activeView)) { p.skipChildren(); continue; prop.deserializeAndSet(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); tokens.writeFieldName(propName); tokens.copyCurrentStructure(p); } else {
return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(p, ctxt)); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); Object bean = _valueInstantiator.createUsingDefault(ctxt); final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; for (; p.getCurrentToken() == JsonToken.FIELD_NAME; p.nextToken()) { String propName = p.getCurrentName(); p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case if (activeView != null && !prop.visibleInView(activeView)) { p.skipChildren(); continue; bean = prop.deserializeSetAndReturn(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); tokens.writeFieldName(propName); tokens.copyCurrentStructure(p);
throws IOException final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; for (JsonToken t = p.getCurrentToken(); t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); SettableBeanProperty prop = _beanProperties.find(propName); p.nextToken(); if (prop != null) { // normal case if (activeView != null && !prop.visibleInView(activeView)) { p.skipChildren(); continue; builder = prop.deserializeSetAndReturn(p, ctxt, builder); } catch (Exception e) { wrapAndThrow(e, builder, propName, ctxt); tokens.writeFieldName(propName); tokens.copyCurrentStructure(p); tokens.writeEndObject(); return _unwrappedPropertyHandler.processUnwrapped(p, ctxt, builder, tokens);
throws IOException final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; final ExternalTypeHandler ext = _externalTypeIdHandler.start(); for (JsonToken t = p.getCurrentToken(); t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); t = p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case ext.handleTypePropertyValue(p, ctxt, propName, bean); if (activeView != null && !prop.visibleInView(activeView)) { p.skipChildren(); continue; prop.deserializeAndSet(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt);
if (p.hasToken(JsonToken.START_OBJECT)) { p.nextToken(); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); return deserializeWithUnwrapped(p, ctxt, builder, tokens); Class<?> view = ctxt.getActiveView(); if (view != null) { return deserializeWithView(p, ctxt, builder, view); JsonToken t = p.getCurrentToken(); p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); builder = prop.deserializeSetAndReturn(p, ctxt, builder); } catch (Exception e) { wrapAndThrow(e, builder, propName, ctxt);
if (p.isExpectedStartObjectToken()) { keyName = p.nextFieldName(); } else if (p.hasToken(JsonToken.FIELD_NAME)) { keyName = p.getCurrentName(); } else { if (prop != null) { if (buffer.assignParameter(prop, prop.deserialize(p, ctxt))) { p.nextToken(); // from value to END_OBJECT or FIELD_NAME EnumMap<?,?> result; result = (EnumMap<?,?>)creator.build(ctxt, buffer); } catch (Exception e) { return wrapAndThrow(e, _containerType.getRawClass(), keyName); if (!ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) { return (EnumMap<?,?>) ctxt.handleWeirdStringValue(_enumClass, keyName, "value not one of declared Enum instance names for %s", _containerType.getKeyType()); wrapAndThrow(e, _containerType.getRawClass(), keyName); return null;
return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(p, ctxt)); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); final Object bean = _valueInstantiator.createUsingDefault(ctxt); p.setCurrentValue(bean); final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; String propName = p.hasTokenId(JsonTokenId.ID_FIELD_NAME) ? p.getCurrentName() : null; for (; propName != null; propName = p.nextFieldName()) { p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case if ((activeView != null) && !prop.visibleInView(activeView)) { p.skipChildren(); continue; prop.deserializeAndSet(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); tokens.writeFieldName(propName); tokens.copyCurrentStructure(p); continue;
protected final Object deserializeWithView(JsonParser p, DeserializationContext ctxt, Object bean, Class<?> activeView) throws IOException { if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) { String propName = p.getCurrentName(); do { p.nextToken(); // TODO: 06-Jan-2015, tatu: try streamlining call sequences here as well SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { if (!prop.visibleInView(activeView)) { p.skipChildren(); continue; } try { prop.deserializeAndSet(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } handleUnknownVanilla(p, ctxt, bean, propName); } while ((propName = p.nextFieldName()) != null); } return bean; }
if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) { String propertyName = p.getCurrentName(); do { p.nextToken(); SettableBeanProperty property = _beanProperties.find(propertyName); Object id = property.deserialize(p, ctxt); ReadableObjectId objectId = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver); bean = _valueInstantiator.createUsingDefault(ctxt); property.set(bean, id); bean = _valueInstantiator.createUsingDefault(ctxt); p.setCurrentValue(bean); property.deserializeAndSet(p, ctxt, bean); } while ((propertyName = p.nextFieldName()) != null);
/** * Streamlined version that is only used when no "special" * features are enabled. */ private final Object vanillaDeserialize(JsonParser p, DeserializationContext ctxt, JsonToken t) throws IOException { final Object bean = _valueInstantiator.createUsingDefault(ctxt); // [databind#631]: Assign current value, to be accessible by custom serializers p.setCurrentValue(bean); if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) { String propName = p.getCurrentName(); do { p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case try { prop.deserializeAndSet(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } handleUnknownVanilla(p, ctxt, bean, propName); } while ((propName = p.nextFieldName()) != null); } return bean; }
if (!p.isExpectedStartArrayToken()) { return _deserializeFromNonArray(p, ctxt); return _deserializeNonVanilla(p, ctxt); final Object bean = _valueInstantiator.createUsingDefault(ctxt); p.setCurrentValue(bean); final int propCount = props.length; while (true) { if (p.nextToken() == JsonToken.END_ARRAY) { return bean; if (prop != null) { // normal case try { prop.deserializeAndSet(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, prop.getName(), ctxt); if (!_ignoreAllUnknown && ctxt.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) { ctxt.reportWrongTokenException(this, JsonToken.END_ARRAY, "Unexpected JSON values; expected at most %d properties (in JSON Array)", propCount);