com.fasterxml.jackson.databind.introspect.AnnotatedConstructor类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中com.fasterxml.jackson.databind.introspect.AnnotatedConstructor类的一些代码示例,展示了AnnotatedConstructor类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotatedConstructor类的具体详情如下:
包路径:com.fasterxml.jackson.databind.introspect.AnnotatedConstructor
类名称:AnnotatedConstructor

AnnotatedConstructor介绍

暂无

代码示例

代码示例来源:origin: redisson/redisson

@Override
public Constructor<?> findSingleArgConstructor(Class<?>... argTypes)
{
  for (AnnotatedConstructor ac : _classInfo.getConstructors()) {
    // This list is already filtered to only include accessible
    /* (note: for now this is a redundant check; but in future
     * that may change; thus leaving here for now)
     */
    if (ac.getParameterCount() == 1) {
      Class<?> actArg = ac.getRawParameterType(0);
      for (Class<?> expArg : argTypes) {
        if (expArg == actArg) {
          return ac.getAnnotated();
        }
      }
    }
  }
  return null;
}

代码示例来源:origin: redisson/redisson

/**
 * Method for collecting basic information on constructor(s) found
 */
protected void _addCreators(Map<String, POJOPropertyBuilder> props)
{
  // can be null if annotation processing is disabled...
  if (!_useAnnotations) {
    return;
  }
  for (AnnotatedConstructor ctor : _classDef.getConstructors()) {
    if (_creatorProperties == null) {
      _creatorProperties = new LinkedList<POJOPropertyBuilder>();
    }
    for (int i = 0, len = ctor.getParameterCount(); i < len; ++i) {
      _addCreatorParam(props, ctor.getParameter(i));
    }
  }
  for (AnnotatedMethod factory : _classDef.getFactoryMethods()) {
    if (_creatorProperties == null) {
      _creatorProperties = new LinkedList<POJOPropertyBuilder>();
    }
    for (int i = 0, len = factory.getParameterCount(); i < len; ++i) {
      _addCreatorParam(props, factory.getParameter(i));
    }
  }
}

代码示例来源:origin: redisson/redisson

@Override
public Object getValue(Object pojo)
  throws UnsupportedOperationException
{
  throw new UnsupportedOperationException("Cannot call getValue() on constructor of "
      +getDeclaringClass().getName());
}

代码示例来源:origin: redisson/redisson

@Override
public Object instantiateBean(boolean fixAccess) {
  AnnotatedConstructor ac = _classInfo.getDefaultConstructor();
  if (ac == null) {
    return null;
  }
  if (fixAccess) {
    ac.fixAccess(_config.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
  }
  try {
    return ac.getAnnotated().newInstance();
  } catch (Exception e) {
    Throwable t = e;
    while (t.getCause() != null) {
      t = t.getCause();
    }
    ClassUtil.throwIfError(t);
    ClassUtil.throwIfRTE(t);
    throw new IllegalArgumentException("Failed to instantiate bean of type "
        +_classInfo.getAnnotated().getName()+": ("+t.getClass().getName()+") "
        +ClassUtil.exceptionMessage(t), t);
  }
}

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

@Override
public Object instantiateBean(boolean fixAccess)
{
  AnnotatedConstructor ac = _classInfo.getDefaultConstructor();
  if (ac == null) {
    return null;
  }
  if (fixAccess) {
    ac.fixAccess();
  }
  try {
    return ac.getAnnotated().newInstance();
  } catch (Exception e) {
    Throwable t = e;
    while (t.getCause() != null) {
      t = t.getCause();
    }
    if (t instanceof Error) throw (Error) t;
    if (t instanceof RuntimeException) throw (RuntimeException) t;
    throw new IllegalArgumentException("Failed to instantiate bean of type "+_classInfo.getAnnotated().getName()+": ("+t.getClass().getName()+") "+t.getMessage(), t);
  }
}

代码示例来源:origin: Nextdoor/bender

/**
 * Method for collecting basic information on constructor(s) found
 */
protected void _addCreators(Map<String, POJOPropertyBuilder> props)
{
  // can be null if annotation processing is disabled...
  if (_annotationIntrospector == null) {
    return;
  }
  for (AnnotatedConstructor ctor : _classDef.getConstructors()) {
    if (_creatorProperties == null) {
      _creatorProperties = new LinkedList<POJOPropertyBuilder>();
    }
    for (int i = 0, len = ctor.getParameterCount(); i < len; ++i) {
      _addCreatorParam(props, ctor.getParameter(i));
    }
  }
  for (AnnotatedMethod factory : _classDef.getStaticMethods()) {
    if (_creatorProperties == null) {
      _creatorProperties = new LinkedList<POJOPropertyBuilder>();
    }
    for (int i = 0, len = factory.getParameterCount(); i < len; ++i) {
      _addCreatorParam(props, factory.getParameter(i));
    }
  }
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

final boolean isCreator = intr.hasCreatorAnnotation(ctor);
BeanPropertyDefinition[] propDefs = creatorParams.get(ctor);
final int argCount = ctor.getParameterCount();
    CreatorProperty[] properties = new CreatorProperty[1];
    PropertyName name = (argDef == null) ? null : argDef.getFullName();
    AnnotatedParameter arg = ctor.getParameter(0);
    properties[0] = constructCreatorProperty(ctxt, beanDesc, name, 0, arg,
        intr.findInjectableValueId(arg));
int injectCount = 0;            
for (int i = 0; i < argCount; ++i) {
  final AnnotatedParameter param = ctor.getParameter(i);
  BeanPropertyDefinition propDef = (propDefs == null) ? null : propDefs[i];
  Object injectId = intr.findInjectableValueId(param);
    if ((ix == 0) && ClassUtil.isNonStaticInnerClass(ctor.getDeclaringClass())) {
      throw new IllegalArgumentException("Non-static inner classes like "
          +ctor.getDeclaringClass().getName()+" can not use @JsonCreator for constructors");

代码示例来源:origin: xebia/jackson-lombok

private void addJacksonAnnotationsToContructorParameters(AnnotatedConstructor annotatedConstructor) {
  ConstructorProperties properties = getConstructorPropertiesAnnotation(annotatedConstructor);
  for (int i = 0; i < annotatedConstructor.getParameterCount(); i++) {
    String name = properties.value()[i];
    AnnotatedParameter parameter = annotatedConstructor.getParameter(i);
    Field field = null;
    try {
      field = annotatedConstructor.getDeclaringClass().getDeclaredField(name);
    } catch (NoSuchFieldException ignored) {
    }
    addJacksonAnnotationsToConstructorParameter(field, parameter, name);
  }
}

代码示例来源:origin: danielnorberg/auto-matter

@Override
 public boolean hasCreatorAnnotation(final Annotated a) {
  if (!(a instanceof AnnotatedConstructor)) {
   return false;
  }
  final AnnotatedConstructor ctor = (AnnotatedConstructor) a;
  if (ctor.getParameterCount() == 0) {
   return true;
  }
  final AutoMatter.Field field = ctor.getParameter(0).getAnnotation(AutoMatter.Field.class);
  return field != null;
 }
}

代码示例来源:origin: FasterXML/jackson-dataformats-binary

@Override
public JsonCreator.Mode findCreatorAnnotation(MapperConfig<?> config, Annotated a) {
  if (a instanceof AnnotatedConstructor) {
    AnnotatedConstructor constructor = (AnnotatedConstructor) a;
    // 09-Mar-2017, tatu: Ideally would allow mix-ins etc, but for now let's take
    //   a short-cut here:
    Class<?> declClass = constructor.getDeclaringClass();
    if (declClass.getAnnotation(Stringable.class) != null) {
       if (constructor.getParameterCount() == 1
           && String.class.equals(constructor.getRawParameterType(0))) {
         return JsonCreator.Mode.DELEGATING;
       }
    }
  }
  return null;
}

代码示例来源:origin: stackoverflow.com

Constructor<?> c = ac.getAnnotated();
ConstructorProperties properties = c.getAnnotation(ConstructorProperties.class);
for (int i = 0; i < ac.getParameterCount(); i++) {
 final String name = properties.value()[i];
 final int index = i;
 ac.getParameter(i).addOrOverride(jsonProperty);

代码示例来源:origin: redisson/redisson

Object readResolve() {
  Class<?> clazz = _serialization.clazz;
  try {
    Constructor<?> ctor = clazz.getDeclaredConstructor(_serialization.args);
    // 06-Oct-2012, tatu: Has "lost" its security override, must force back
    if (!ctor.isAccessible()) {
      ClassUtil.checkAndFixAccess(ctor, false);
    }
    return new AnnotatedConstructor(null, ctor, null, null);
  } catch (Exception e) {
    throw new IllegalArgumentException("Could not find constructor with "
        +_serialization.args.length+" args from Class '"+clazz.getName());
  }
}

代码示例来源:origin: redisson/redisson

/**
 * Constructor used with JDK Serialization; needed to handle transient
 * Constructor, wrap/unwrap in/out-of Annotated variant.
 */
protected InnerClassProperty(SettableBeanProperty src, AnnotatedConstructor ann)
{
  super(src);
  _annotated = ann;
  _creator = (_annotated == null) ? null : _annotated.getAnnotated();
  if (_creator == null) {
    throw new IllegalArgumentException("Missing constructor (broken JDK (de)serialization?)");
  }
}

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

AnnotatedParameter param = ctor.getParameter(0);
String name = intr.findDeserializationName(param);
Object injectId = intr.findInjectableValueId(param);
Class<?> type = ctor.getRawParameterType(0);
if (type == String.class) {
  if (isCreator || isVisible) {

代码示例来源:origin: redisson/redisson

@Override
public AnnotatedConstructor withAnnotations(AnnotationMap ann) {
  return new AnnotatedConstructor(_typeContext, _constructor, ann, _paramAnnotations);
}

代码示例来源:origin: Nextdoor/bender

protected void _addConstructorMixIns(Class<?> mixin)
{
  MemberKey[] ctorKeys = null;
  int ctorCount = (_constructors == null) ? 0 : _constructors.size();
  for (ClassUtil.Ctor ctor0 : ClassUtil.getConstructors(mixin)) {
    Constructor<?> ctor = ctor0.getConstructor();
    if (ctor.getParameterTypes().length == 0) {
      if (_defaultConstructor != null) {
        _addMixOvers(ctor, _defaultConstructor, false);
      }
    } else {
      if (ctorKeys == null) {
        ctorKeys = new MemberKey[ctorCount];
        for (int i = 0; i < ctorCount; ++i) {
          ctorKeys[i] = new MemberKey(_constructors.get(i).getAnnotated());
        }
      }
      MemberKey key = new MemberKey(ctor);
      for (int i = 0; i < ctorCount; ++i) {
        if (!key.equals(ctorKeys[i])) {
          continue;
        }
        _addMixOvers(ctor, _constructors.get(i), true);
        break;
      }
    }
  }
}

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

if (defaultCtor != null) {
  if (fixAccess) {
    ClassUtil.checkAndFixAccess(defaultCtor.getAnnotated());

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

/**
 * @param addParamAnnotations Whether parameter annotations are to be
 *   added as well
 */
protected void _addMixOvers(Constructor<?> mixin, AnnotatedConstructor target,
    boolean addParamAnnotations)
{
  _addOrOverrideAnnotations(target, mixin.getDeclaredAnnotations());
  if (addParamAnnotations) {
    Annotation[][] pa = mixin.getParameterAnnotations();
    for (int i = 0, len = pa.length; i < len; ++i) {
      for (Annotation a : pa[i]) {
        target.addOrOverrideParam(i, a);
      }
    }
  }
}

代码示例来源:origin: Nextdoor/bender

protected AnnotatedConstructor _constructDefaultConstructor(ClassUtil.Ctor ctor,
    TypeResolutionContext typeContext)
{
  if (_annotationIntrospector == null) { // when annotation processing is disabled
    return new AnnotatedConstructor(typeContext, ctor.getConstructor(), _emptyAnnotationMap(), NO_ANNOTATION_MAPS);
  }
  return new AnnotatedConstructor(typeContext, ctor.getConstructor(),
      _collectRelevantAnnotations(ctor.getDeclaredAnnotations()), NO_ANNOTATION_MAPS);
}

代码示例来源:origin: redisson/redisson

@Override
public JavaType getType() {
  return _typeContext.resolveType(getRawType());
}

相关文章