Search in sources :

Example 1 with BeanPropertyMap

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

the class BeanDeserializerBuilder method buildBuilderBased.

/**
     * Method for constructing a specialized deserializer that uses
     * additional external Builder object during data binding.
     */
public JsonDeserializer<?> buildBuilderBased(JavaType valueType, String expBuildMethodName) throws JsonMappingException {
    // First: validation; must have build method that returns compatible type
    if (_buildMethod == null) {
        // as per [databind#777], allow empty name
        if (!expBuildMethodName.isEmpty()) {
            _context.reportBadDefinition(_beanDesc.getType(), String.format("Builder class %s does not have build method (name: '%s')", _beanDesc.getBeanClass().getName(), expBuildMethodName));
        }
    } else {
        // also: type of the method must be compatible
        Class<?> rawBuildType = _buildMethod.getRawReturnType();
        Class<?> rawValueType = valueType.getRawClass();
        if ((rawBuildType != rawValueType) && !rawBuildType.isAssignableFrom(rawValueType) && !rawValueType.isAssignableFrom(rawBuildType)) {
            _context.reportBadDefinition(_beanDesc.getType(), String.format("Build method '%s' has wrong return type (%s), not compatible with POJO type (%s)", _buildMethod.getFullName(), rawBuildType.getName(), valueType.getRawClass().getName()));
        }
    }
    // And if so, we can try building the deserializer
    Collection<SettableBeanProperty> props = _properties.values();
    _fixAccess(props);
    BeanPropertyMap propertyMap = BeanPropertyMap.construct(props, _config.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES), _collectAliases(props));
    propertyMap.assignIndexes();
    boolean anyViews = !_config.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION);
    if (!anyViews) {
        for (SettableBeanProperty prop : props) {
            if (prop.hasViews()) {
                anyViews = true;
                break;
            }
        }
    }
    if (_objectIdReader != null) {
        // May or may not have annotations for id property; but no easy access.
        // But hard to see id property being optional, so let's consider required at this point.
        ObjectIdValueProperty prop = new ObjectIdValueProperty(_objectIdReader, PropertyMetadata.STD_REQUIRED);
        propertyMap = propertyMap.withProperty(prop);
    }
    return new BuilderBasedDeserializer(this, _beanDesc, valueType, propertyMap, _backRefProperties, _ignorableProps, _ignoreAllUnknown, anyViews);
}
Also used : BeanPropertyMap(com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap) ObjectIdValueProperty(com.fasterxml.jackson.databind.deser.impl.ObjectIdValueProperty)

Example 2 with BeanPropertyMap

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

the class BeanDeserializerBuilder method build.

/*
    /**********************************************************
    /* Build method(s)
    /**********************************************************
     */
/**
     * Method for constructing a {@link BeanDeserializer}, given all
     * information collected.
     */
public JsonDeserializer<?> build() {
    Collection<SettableBeanProperty> props = _properties.values();
    _fixAccess(props);
    BeanPropertyMap propertyMap = BeanPropertyMap.construct(props, _config.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES), _collectAliases(props));
    propertyMap.assignIndexes();
    // view processing must be enabled if:
    // (a) fields are not included by default (when deserializing with view), OR
    // (b) one of properties has view(s) to included in defined
    boolean anyViews = !_config.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION);
    if (!anyViews) {
        for (SettableBeanProperty prop : props) {
            if (prop.hasViews()) {
                anyViews = true;
                break;
            }
        }
    }
    // one more thing: may need to create virtual ObjectId property:
    if (_objectIdReader != null) {
        /* 18-Nov-2012, tatu: May or may not have annotations for id property;
             *   but no easy access. But hard to see id property being optional,
             *   so let's consider required at this point.
             */
        ObjectIdValueProperty prop = new ObjectIdValueProperty(_objectIdReader, PropertyMetadata.STD_REQUIRED);
        propertyMap = propertyMap.withProperty(prop);
    }
    return new BeanDeserializer(this, _beanDesc, propertyMap, _backRefProperties, _ignorableProps, _ignoreAllUnknown, anyViews);
}
Also used : BeanPropertyMap(com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap) ObjectIdValueProperty(com.fasterxml.jackson.databind.deser.impl.ObjectIdValueProperty)

Example 3 with BeanPropertyMap

use of com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap 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)

Aggregations

BeanPropertyMap (com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap)3 ObjectIdValueProperty (com.fasterxml.jackson.databind.deser.impl.ObjectIdValueProperty)3 SettableBeanProperty (com.fasterxml.jackson.databind.deser.SettableBeanProperty)1