com.fasterxml.jackson.annotation.JacksonInject#Value ( )源码实例Demo

下面列出了com.fasterxml.jackson.annotation.JacksonInject#Value ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lams   文件: POJOPropertiesCollector.java
protected void _doAddInjectable(JacksonInject.Value injectable, AnnotatedMember m)
{
    if (injectable == null) {
        return;
    }
    Object id = injectable.getId();
    if (_injectables == null) {
        _injectables = new LinkedHashMap<Object, AnnotatedMember>();
    }
    AnnotatedMember prev = _injectables.put(id, m);
    if (prev != null) {
        // 12-Apr-2017, tatu: Let's allow masking of Field by Method
        if (prev.getClass() == m.getClass()) {
            String type = id.getClass().getName();
            throw new IllegalArgumentException("Duplicate injectable value with id '"
                    +String.valueOf(id)+"' (of type "+type+")");
        }
    }
}
 
源代码2 项目: lams   文件: BasicDeserializerFactory.java
/**
     * Helper method called when there is the explicit "is-creator" with mode of "properties-based"
     *
     * @since 2.9.2
     */
    protected void _addExplicitPropertyCreator(DeserializationContext ctxt,
            BeanDescription beanDesc, CreatorCollector creators,
            CreatorCandidate candidate)
        throws JsonMappingException
    {
        final int paramCount = candidate.paramCount();
        SettableBeanProperty[] properties = new SettableBeanProperty[paramCount];

        for (int i = 0; i < paramCount; ++i) {
            JacksonInject.Value injectId = candidate.injection(i);
            AnnotatedParameter param = candidate.parameter(i);
            PropertyName name = candidate.paramName(i);
            if (name == null) {
                // 21-Sep-2017, tatu: Looks like we want to block accidental use of Unwrapped,
                //   as that will not work with Creators well at all
                NameTransformer unwrapper = ctxt.getAnnotationIntrospector().findUnwrappingNameTransformer(param);
                if (unwrapper != null) {
                    _reportUnwrappedCreatorProperty(ctxt, beanDesc, param);
                    /*
                    properties[i] = constructCreatorProperty(ctxt, beanDesc, UNWRAPPED_CREATOR_PARAM_NAME, i, param, null);
                    ++explicitNameCount;
                    */
                }
                name = candidate.findImplicitParamName(i);
                // Must be injectable or have name; without either won't work
                if ((name == null) && (injectId == null)) {
                    ctxt.reportBadTypeDefinition(beanDesc,
"Argument #%d has no property name, is not Injectable: can not use as Creator %s", i, candidate);
                }
            }
            properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
        }
        creators.addPropertyCreator(candidate.creator(), true, properties);
    }
 
源代码3 项目: lams   文件: CreatorCandidate.java
public static CreatorCandidate construct(AnnotationIntrospector intr,
        AnnotatedWithParams creator, BeanPropertyDefinition[] propDefs)
{
    final int pcount = creator.getParameterCount();
    Param[] params = new Param[pcount];
    for (int i = 0; i < pcount; ++i) {
        AnnotatedParameter annParam = creator.getParameter(i);
        JacksonInject.Value injectId = intr.findInjectableValue(annParam);
        params[i] = new Param(annParam, (propDefs == null) ? null : propDefs[i], injectId);
    }
    return new CreatorCandidate(intr, creator, params, pcount);
}
 
源代码4 项目: lams   文件: CreatorCandidate.java
public Param(AnnotatedParameter p, BeanPropertyDefinition pd,
        JacksonInject.Value i)
{
    annotated = p;
    propDef = pd;
    injection = i;
}
 
@Override // since 2.9
public JacksonInject.Value findInjectableValue(MapperConfig<?> config, AnnotatedMember m) {
    Object id = _findGuiceInjectId(m);
    if (id == null) {
        return null;
    }
    return JacksonInject.Value.forId(id);
}
 
源代码6 项目: lams   文件: AnnotationIntrospectorPair.java
@Override
public JacksonInject.Value findInjectableValue(AnnotatedMember m) {
    JacksonInject.Value r = _primary.findInjectableValue(m);
    return (r == null) ? _secondary.findInjectableValue(m) : r;
}
 
源代码7 项目: lams   文件: BasicDeserializerFactory.java
/**
 * Helper method called when there is the explicit "is-creator" with mode of "delegating"
 *
 * @since 2.9.2
 */
protected void _addExplicitDelegatingCreator(DeserializationContext ctxt,
        BeanDescription beanDesc, CreatorCollector creators,
        CreatorCandidate candidate)
    throws JsonMappingException
{
    // Somewhat simple: find injectable values, if any, ensure there is one
    // and just one delegated argument; report violations if any

    int ix = -1;
    final int argCount = candidate.paramCount();
    SettableBeanProperty[] properties = new SettableBeanProperty[argCount];
    for (int i = 0; i < argCount; ++i) {
        AnnotatedParameter param = candidate.parameter(i);
        JacksonInject.Value injectId = candidate.injection(i);
        if (injectId != null) {
            properties[i] = constructCreatorProperty(ctxt, beanDesc, null, i, param, injectId);
            continue;
        }
        if (ix < 0) {
            ix = i;
            continue;
        }
        // Illegal to have more than one value to delegate to
        ctxt.reportBadTypeDefinition(beanDesc,
                "More than one argument (#%d and #%d) left as delegating for Creator %s: only one allowed",
                ix, i, candidate);
    }
    // Also, let's require that one Delegating argument does eixt
    if (ix < 0) {
        ctxt.reportBadTypeDefinition(beanDesc,
                "No argument left as delegating for Creator %s: exactly one required", candidate);
    }
    // 17-Jan-2018, tatu: as per [databind#1853] need to ensure we will distinguish
    //   "well-known" single-arg variants (String, int/long, boolean) from "generic" delegating...
    if (argCount == 1) {
        _handleSingleArgumentCreator(creators, candidate.creator(), true, true);
        // one more thing: sever link to creator property, to avoid possible later
        // problems with "unresolved" constructor property
        BeanPropertyDefinition paramDef = candidate.propertyDef(0);
        if (paramDef != null) {
            ((POJOPropertyBuilder) paramDef).removeConstructors();
        }
        return;
    }
    creators.addDelegatingCreator(candidate.creator(), true, properties, ix);
}
 
源代码8 项目: lams   文件: BasicDeserializerFactory.java
/**
 * Method that will construct a property object that represents
 * a logical property passed via Creator (constructor or static
 * factory method)
 */
protected SettableBeanProperty constructCreatorProperty(DeserializationContext ctxt,
        BeanDescription beanDesc, PropertyName name, int index,
        AnnotatedParameter param,
        JacksonInject.Value injectable)
    throws JsonMappingException
{
    final DeserializationConfig config = ctxt.getConfig();
    final AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
    PropertyMetadata metadata;
    {
        if (intr == null) {
            metadata = PropertyMetadata.STD_REQUIRED_OR_OPTIONAL;
        } else {
            Boolean b = intr.hasRequiredMarker(param);
            String desc = intr.findPropertyDescription(param);
            Integer idx = intr.findPropertyIndex(param);
            String def = intr.findPropertyDefaultValue(param);
            metadata = PropertyMetadata.construct(b, desc, idx, def);
        }
    }
    JavaType type = resolveMemberAndTypeAnnotations(ctxt, param, param.getType());
    BeanProperty.Std property = new BeanProperty.Std(name, type,
            intr.findWrapperName(param), param, metadata);
    // Type deserializer: either comes from property (and already resolved)
    TypeDeserializer typeDeser = (TypeDeserializer) type.getTypeHandler();
    // or if not, based on type being referenced:
    if (typeDeser == null) {
        typeDeser = findTypeDeserializer(config, type);
    }
    // Note: contextualization of typeDeser _should_ occur in constructor of CreatorProperty
    // so it is not called directly here

    Object injectableValueId = (injectable == null) ? null : injectable.getId();
    
    SettableBeanProperty prop = new CreatorProperty(name, type, property.getWrapperName(),
            typeDeser, beanDesc.getClassAnnotations(), param, index, injectableValueId,
            metadata);
    JsonDeserializer<?> deser = findDeserializerFromAnnotation(ctxt, param);
    if (deser == null) {
        deser = type.getValueHandler();
    }
    if (deser != null) {
        // As per [databind#462] need to ensure we contextualize deserializer before passing it on
        deser = ctxt.handlePrimaryContextualization(deser, prop, type);
        prop = prop.withValueDeserializer(deser);
    }
    return prop;
}
 
源代码9 项目: lams   文件: CreatorCandidate.java
public JacksonInject.Value injection(int i) { return _params[i].injection; }