Search in sources :

Example 16 with SettableBeanProperty

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

the class BeanPropertyMap method init.

protected void init(Collection<SettableBeanProperty> props) {
    _size = props.size();
    // First: calculate size of primary hash area
    final int hashSize = findSize(_size);
    _hashMask = hashSize - 1;
    // and allocate enough to contain primary/secondary, expand for spillovers as need be
    int alloc = (hashSize + (hashSize >> 1)) * 2;
    Object[] hashed = new Object[alloc];
    int spillCount = 0;
    for (SettableBeanProperty prop : props) {
        // Due to removal, renaming, theoretically possible we'll have "holes" so:
        if (prop == null) {
            continue;
        }
        String key = getPropertyName(prop);
        int slot = _hashCode(key);
        int ix = (slot << 1);
        // primary slot not free?
        if (hashed[ix] != null) {
            // secondary?
            ix = (hashSize + (slot >> 1)) << 1;
            if (hashed[ix] != null) {
                // ok, spill over.
                ix = ((hashSize + (hashSize >> 1)) << 1) + spillCount;
                spillCount += 2;
                if (ix >= hashed.length) {
                    hashed = Arrays.copyOf(hashed, hashed.length + 4);
                }
            }
        }
        //System.err.println(" add '"+key+" at #"+(ix>>1)+"/"+size+" (hashed at "+slot+")");             
        hashed[ix] = key;
        hashed[ix + 1] = prop;
    // and aliases
    }
    /*
for (int i = 0; i < hashed.length; i += 2) {
System.err.printf("#%02d: %s\n", i>>1, (hashed[i] == null) ? "-" : hashed[i]);
}
*/
    _hashArea = hashed;
    _spillCount = spillCount;
}
Also used : SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

Example 17 with SettableBeanProperty

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

the class BeanPropertyMap method toString.

/*
    /**********************************************************
    /* Std method overrides
    /**********************************************************
     */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("Properties=[");
    int count = 0;
    Iterator<SettableBeanProperty> it = iterator();
    while (it.hasNext()) {
        SettableBeanProperty prop = it.next();
        if (count++ > 0) {
            sb.append(", ");
        }
        sb.append(prop.getName());
        sb.append('(');
        sb.append(prop.getType());
        sb.append(')');
    }
    sb.append(']');
    if (!_aliasDefs.isEmpty()) {
        sb.append("(aliases: ");
        sb.append(_aliasDefs);
        sb.append(")");
    }
    return sb.toString();
}
Also used : SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

Example 18 with SettableBeanProperty

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

the class BeanPropertyMap method remove.

/**
     * Specialized method for removing specified existing entry.
     * NOTE: entry MUST exist, otherwise an exception is thrown.
     */
public void remove(SettableBeanProperty propToRm) {
    ArrayList<SettableBeanProperty> props = new ArrayList<SettableBeanProperty>(_size);
    String key = getPropertyName(propToRm);
    boolean found = false;
    for (int i = 1, end = _hashArea.length; i < end; i += 2) {
        SettableBeanProperty prop = (SettableBeanProperty) _hashArea[i];
        if (prop == null) {
            continue;
        }
        if (!found) {
            // 09-Jan-2017, tatu: Important: must check name slot and NOT property name,
            //   as only former is lower-case in case-insensitive case
            found = key.equals(_hashArea[i - 1]);
            if (found) {
                // need to leave a hole here
                _propsInOrder[_findFromOrdered(prop)] = null;
                continue;
            }
        }
        props.add(prop);
    }
    if (!found) {
        throw new NoSuchElementException("No entry '" + propToRm.getName() + "' found, can't remove");
    }
    init(props);
}
Also used : SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

Example 19 with SettableBeanProperty

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

the class ExternalTypeHandler method complete.

/**
     * Method called after JSON Object closes, and has to ensure that all external
     * type ids have been handled.
     */
@SuppressWarnings("resource")
public Object complete(JsonParser p, DeserializationContext ctxt, Object bean) throws IOException {
    for (int i = 0, len = _properties.length; i < len; ++i) {
        String typeId = _typeIds[i];
        if (typeId == null) {
            TokenBuffer tokens = _tokens[i];
            // but not just one
            if (tokens == null) {
                continue;
            }
            // [databind#118]: Need to mind natural types, for which no type id
            // will be included.
            JsonToken t = tokens.firstToken();
            if (t.isScalarValue()) {
                // can't be null as we never store empty buffers
                JsonParser buffered = tokens.asParser(p);
                buffered.nextToken();
                SettableBeanProperty extProp = _properties[i].getProperty();
                Object result = TypeDeserializer.deserializeIfNatural(buffered, ctxt, extProp.getType());
                if (result != null) {
                    extProp.set(bean, result);
                    continue;
                }
                // 26-Oct-2012, tatu: As per [databind#94], must allow use of 'defaultImpl'
                if (!_properties[i].hasDefaultType()) {
                    ctxt.reportInputMismatch(bean.getClass(), "Missing external type id property '%s'", _properties[i].getTypePropertyName());
                } else {
                    typeId = _properties[i].getDefaultTypeId();
                }
            }
        } else if (_tokens[i] == null) {
            SettableBeanProperty prop = _properties[i].getProperty();
            if (prop.isRequired() || ctxt.isEnabled(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY)) {
                ctxt.reportInputMismatch(bean.getClass(), "Missing property '%s' for external type id '%s'", prop.getName(), _properties[i].getTypePropertyName());
            }
            return bean;
        }
        _deserializeAndSet(p, ctxt, bean, i, typeId);
    }
    return bean;
}
Also used : SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty) TokenBuffer(com.fasterxml.jackson.databind.util.TokenBuffer)

Example 20 with SettableBeanProperty

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

the class UnwrappedPropertyHandler method renameAll.

public UnwrappedPropertyHandler renameAll(NameTransformer transformer) {
    ArrayList<SettableBeanProperty> newProps = new ArrayList<SettableBeanProperty>(_properties.size());
    for (SettableBeanProperty prop : _properties) {
        String newName = transformer.transform(prop.getName());
        prop = prop.withSimpleName(newName);
        JsonDeserializer<?> deser = prop.getValueDeserializer();
        if (deser != null) {
            @SuppressWarnings("unchecked") JsonDeserializer<Object> newDeser = (JsonDeserializer<Object>) deser.unwrappingDeserializer(transformer);
            if (newDeser != deser) {
                prop = prop.withValueDeserializer(newDeser);
            }
        }
        newProps.add(prop);
    }
    return new UnwrappedPropertyHandler(newProps);
}
Also used : SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer)

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