Search in sources :

Example 11 with SettableBeanProperty

use of com.fasterxml.jackson.databind.deser.SettableBeanProperty in project jackson-databind by FasterXML.

the class PropertyValueBuffer method handleIdValue.

/**
     * Helper method called to handle Object Id value collected earlier, if any
     */
public Object handleIdValue(final DeserializationContext ctxt, Object bean) throws IOException {
    if (_objectIdReader != null) {
        if (_idValue != null) {
            ReadableObjectId roid = ctxt.findObjectId(_idValue, _objectIdReader.generator, _objectIdReader.resolver);
            roid.bindItem(bean);
            // also: may need to set a property value as well
            SettableBeanProperty idProp = _objectIdReader.idProperty;
            if (idProp != null) {
                return idProp.setAndReturn(bean, _idValue);
            }
        } else {
            // 07-Jun-2016, tatu: Trying to improve error messaging here...
            ctxt.reportUnresolvedObjectId(_objectIdReader, bean);
        }
    }
    return bean;
}
Also used : SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

Example 12 with SettableBeanProperty

use of com.fasterxml.jackson.databind.deser.SettableBeanProperty in project jackson-databind by FasterXML.

the class BeanPropertyMapTest method testArrayOutOfBounds884.

// Highly specialized test in which we get couple of hash collisions for
// small (16) hash map
public void testArrayOutOfBounds884() throws Exception {
    List<SettableBeanProperty> props = new ArrayList<SettableBeanProperty>();
    PropertyMetadata md = PropertyMetadata.STD_REQUIRED;
    props.add(new ObjectIdValueProperty(new MyObjectIdReader("pk"), md));
    props.add(new ObjectIdValueProperty(new MyObjectIdReader("firstName"), md));
    BeanPropertyMap propMap = new BeanPropertyMap(false, props, new HashMap<String, List<PropertyName>>());
    propMap = propMap.withProperty(new ObjectIdValueProperty(new MyObjectIdReader("@id"), md));
    assertNotNull(propMap);
}
Also used : SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty) BeanPropertyMap(com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap) ObjectIdValueProperty(com.fasterxml.jackson.databind.deser.impl.ObjectIdValueProperty)

Example 13 with SettableBeanProperty

use of com.fasterxml.jackson.databind.deser.SettableBeanProperty in project requery by requery.

the class EntityBeanDeserializer method deserializeFromObject.

@Override
public Object deserializeFromObject(JsonParser p, DeserializationContext ctxt) throws IOException {
    if (_nonStandardCreation || _needViewProcesing) {
        return super.deserializeFromObject(p, ctxt);
    }
    Object bean = null;
    if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) {
        String propertyName = p.getCurrentName();
        do {
            p.nextToken();
            SettableBeanProperty property = _beanProperties.find(propertyName);
            if (property == null) {
                handleUnknownVanilla(p, ctxt, bean, propertyName);
                continue;
            }
            // lazily create the bean, the id property must be the first property
            if (bean == null) {
                if (propertyName.equals(_objectIdReader.propertyName.getSimpleName())) {
                    // deserialize id
                    Object id = property.deserialize(p, ctxt);
                    ReadableObjectId objectId = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
                    bean = objectId == null ? null : objectId.resolve();
                    if (bean == null) {
                        bean = _valueInstantiator.createUsingDefault(ctxt);
                        property.set(bean, id);
                    }
                } else {
                    bean = _valueInstantiator.createUsingDefault(ctxt);
                }
                p.setCurrentValue(bean);
            }
            property.deserializeAndSet(p, ctxt, bean);
        } while ((propertyName = p.nextFieldName()) != null);
    }
    return bean;
}
Also used : ReadableObjectId(com.fasterxml.jackson.databind.deser.impl.ReadableObjectId) SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

Example 14 with SettableBeanProperty

use of com.fasterxml.jackson.databind.deser.SettableBeanProperty in project jackson-databind by FasterXML.

the class EnumMapDeserializer method _deserializeUsingProperties.

public EnumMap<?, ?> _deserializeUsingProperties(JsonParser p, DeserializationContext ctxt) throws IOException {
    final PropertyBasedCreator creator = _propertyBasedCreator;
    // null -> no ObjectIdReader for EnumMaps
    PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, null);
    String keyName;
    if (p.isExpectedStartObjectToken()) {
        keyName = p.nextFieldName();
    } else if (p.hasToken(JsonToken.FIELD_NAME)) {
        keyName = p.getCurrentName();
    } else {
        keyName = null;
    }
    for (; keyName != null; keyName = p.nextFieldName()) {
        // to get to value
        JsonToken t = p.nextToken();
        // creator property?
        SettableBeanProperty prop = creator.findCreatorProperty(keyName);
        if (prop != null) {
            // Last property to set?
            if (buffer.assignParameter(prop, prop.deserialize(p, ctxt))) {
                EnumMap<?, ?> result;
                try {
                    result = (EnumMap<?, ?>) creator.build(ctxt, buffer);
                } catch (Exception e) {
                    return wrapAndThrow(e, _containerType.getRawClass(), keyName);
                }
                return deserialize(p, ctxt, result);
            }
            continue;
        }
        // other property? needs buffering
        // but we need to let key deserializer handle it separately, nonetheless
        Enum<?> key = (Enum<?>) _keyDeserializer.deserializeKey(keyName, ctxt);
        if (key == null) {
            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());
            }
            // 24-Mar-2012, tatu: Null won't work as a key anyway, so let's
            //  just skip the entry then. But we must skip the value as well, if so.
            p.nextToken();
            p.skipChildren();
            continue;
        }
        Object value;
        try {
            if (t == JsonToken.VALUE_NULL) {
                if (_skipNullValues) {
                    continue;
                }
                value = _nullProvider.getNullValue(ctxt);
            } else if (_valueTypeDeserializer == null) {
                value = _valueDeserializer.deserialize(p, ctxt);
            } else {
                value = _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer);
            }
        } catch (Exception e) {
            wrapAndThrow(e, _containerType.getRawClass(), keyName);
            return null;
        }
        buffer.bufferMapProperty(key, value);
    }
    // if so, can just construct and leave...
    try {
        return (EnumMap<?, ?>) creator.build(ctxt, buffer);
    } catch (Exception e) {
        wrapAndThrow(e, _containerType.getRawClass(), keyName);
        return null;
    }
}
Also used : PropertyValueBuffer(com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer) SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty) PropertyBasedCreator(com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator) IOException(java.io.IOException)

Example 15 with SettableBeanProperty

use of com.fasterxml.jackson.databind.deser.SettableBeanProperty in project jackson-databind by FasterXML.

the class FactoryBasedEnumDeserializer method deserializeEnumUsingPropertyBased.

// Method to deserialize the Enum using property based methodology
protected Object deserializeEnumUsingPropertyBased(final JsonParser p, final DeserializationContext ctxt, final PropertyBasedCreator creator) throws IOException {
    PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, null);
    JsonToken t = p.getCurrentToken();
    for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
        String propName = p.getCurrentName();
        // to point to value
        p.nextToken();
        SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
        if (creatorProp != null) {
            buffer.assignParameter(creatorProp, _deserializeWithErrorWrapping(p, ctxt, creatorProp));
            continue;
        }
        if (buffer.readIdProperty(propName)) {
            continue;
        }
    }
    return creator.build(ctxt, buffer);
}
Also used : PropertyValueBuffer(com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer) SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty) JsonToken(com.fasterxml.jackson.core.JsonToken)

Aggregations

SettableBeanProperty (com.fasterxml.jackson.databind.deser.SettableBeanProperty)21 PropertyValueBuffer (com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)1 BeanPropertyMap (com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap)1 ObjectIdValueProperty (com.fasterxml.jackson.databind.deser.impl.ObjectIdValueProperty)1 PropertyBasedCreator (com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator)1 ReadableObjectId (com.fasterxml.jackson.databind.deser.impl.ReadableObjectId)1 TokenBuffer (com.fasterxml.jackson.databind.util.TokenBuffer)1 IOException (java.io.IOException)1