Search in sources :

Example 1 with SettableBeanProperty

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

the class BeanPropertyMap method replace.

/**
     * Specialized method that can be used to replace an existing entry
     * (note: entry MUST exist; otherwise exception is thrown) with
     * specified replacement.
     */
public void replace(SettableBeanProperty newProp) {
    String key = getPropertyName(newProp);
    int ix = _findIndexInHash(key);
    if (ix < 0) {
        throw new NoSuchElementException("No entry '" + key + "' found, can't replace");
    }
    SettableBeanProperty prop = (SettableBeanProperty) _hashArea[ix];
    _hashArea[ix] = newProp;
    // also, replace in in-order
    _propsInOrder[_findFromOrdered(prop)] = newProp;
}
Also used : SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

Example 2 with SettableBeanProperty

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

the class BeanPropertyMap method withoutProperties.

/*
    /**********************************************************
    /* Public API, mutators
    /**********************************************************
     */
/**
     * Mutant factory method that will use this instance as the base, and
     * construct an instance that is otherwise same except for excluding
     * properties with specified names.
     *
     * @since 2.8
     */
public BeanPropertyMap withoutProperties(Collection<String> toExclude) {
    if (toExclude.isEmpty()) {
        return this;
    }
    final int len = _propsInOrder.length;
    ArrayList<SettableBeanProperty> newProps = new ArrayList<SettableBeanProperty>(len);
    for (int i = 0; i < len; ++i) {
        SettableBeanProperty prop = _propsInOrder[i];
        //   prune them out
        if (prop != null) {
            // may contain holes, too, check.
            if (!toExclude.contains(prop.getName())) {
                newProps.add(prop);
            }
        }
    }
    // should we try to re-index? Apparently no need
    return new BeanPropertyMap(_caseInsensitive, newProps, _aliasDefs);
}
Also used : SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

Example 3 with SettableBeanProperty

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

the class BeanPropertyMap method withProperty.

/**
     * Fluent copy method that creates a new instance that is a copy
     * of this instance except for one additional property that is
     * passed as the argument.
     * Note that method does not modify this instance but constructs
     * and returns a new one.
     */
public BeanPropertyMap withProperty(SettableBeanProperty newProp) {
    // First: may be able to just replace?
    String key = getPropertyName(newProp);
    for (int i = 1, end = _hashArea.length; i < end; i += 2) {
        SettableBeanProperty prop = (SettableBeanProperty) _hashArea[i];
        if ((prop != null) && prop.getName().equals(key)) {
            _hashArea[i] = newProp;
            _propsInOrder[_findFromOrdered(prop)] = newProp;
            return this;
        }
    }
    // If not, append
    final int slot = _hashCode(key);
    final int hashSize = _hashMask + 1;
    int ix = (slot << 1);
    // primary slot not free?
    if (_hashArea[ix] != null) {
        // secondary?
        ix = (hashSize + (slot >> 1)) << 1;
        if (_hashArea[ix] != null) {
            // ok, spill over.
            ix = ((hashSize + (hashSize >> 1)) << 1) + _spillCount;
            _spillCount += 2;
            if (ix >= _hashArea.length) {
                _hashArea = Arrays.copyOf(_hashArea, _hashArea.length + 4);
            // Uncomment for debugging only
            /*
for (int i = 0; i < _hashArea.length; i += 2) {
    if (_hashArea[i] != null) {
        System.err.println("Property #"+(i/2)+" '"+_hashArea[i]+"'...");
    }
}
System.err.println("And new propr #"+slot+" '"+key+"'");
*/
            }
        }
    }
    _hashArea[ix] = key;
    _hashArea[ix + 1] = newProp;
    int last = _propsInOrder.length;
    _propsInOrder = Arrays.copyOf(_propsInOrder, last + 1);
    _propsInOrder[last] = newProp;
    return this;
}
Also used : SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

Example 4 with SettableBeanProperty

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

the class BeanPropertyMap method renameAll.

/**
     * Mutant factory method for constructing a map where all entries use given
     * prefix
     */
public BeanPropertyMap renameAll(NameTransformer transformer) {
    if (transformer == null || (transformer == NameTransformer.NOP)) {
        return this;
    }
    // Try to retain insertion ordering as well
    final int len = _propsInOrder.length;
    ArrayList<SettableBeanProperty> newProps = new ArrayList<SettableBeanProperty>(len);
    for (int i = 0; i < len; ++i) {
        SettableBeanProperty prop = _propsInOrder[i];
        // What to do with holes? For now, retain
        if (prop == null) {
            newProps.add(prop);
            continue;
        }
        newProps.add(_rename(prop, transformer));
    }
    // 26-Feb-2017, tatu: Probably SHOULD handle renaming wrt Aliases?
    return new BeanPropertyMap(_caseInsensitive, newProps, _aliasDefs);
}
Also used : SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

Example 5 with SettableBeanProperty

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

the class JsonLocationInstantiator method getFromObjectArguments.

@Override
public SettableBeanProperty[] getFromObjectArguments(DeserializationConfig config) {
    JavaType intType = config.constructType(Integer.TYPE);
    JavaType longType = config.constructType(Long.TYPE);
    return new SettableBeanProperty[] { creatorProp("sourceRef", config.constructType(Object.class), 0), creatorProp("byteOffset", longType, 1), creatorProp("charOffset", longType, 2), creatorProp("lineNr", intType, 3), creatorProp("columnNr", intType, 4) };
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) SettableBeanProperty(com.fasterxml.jackson.databind.deser.SettableBeanProperty)

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