Пример #1
0
  /**
   * Method that will collect all member (non-static) fields that are either public, or have at
   * least a single annotation associated with them.
   *
   * @param collectIgnored Whether to collect list of ignored methods for later retrieval
   */
  public void resolveFields(boolean collectIgnored) {
    LinkedHashMap<String, AnnotatedField> foundFields = new LinkedHashMap<String, AnnotatedField>();
    _addFields(foundFields, _class);

    /* And last but not least: let's remove all fields that are
     * deemed to be ignorable after all annotations have been
     * properly collapsed.
     */
    Iterator<Map.Entry<String, AnnotatedField>> it = foundFields.entrySet().iterator();
    while (it.hasNext()) {
      AnnotatedField f = it.next().getValue();
      if (_annotationIntrospector.isIgnorableField(f)) {
        it.remove();
        if (collectIgnored) {
          _ignoredFields = ArrayBuilders.addToList(_ignoredFields, f);
        }
      } else {

      }
    }
    if (foundFields.isEmpty()) {
      _fields = Collections.emptyList();
    } else {
      _fields = new ArrayList<AnnotatedField>(foundFields.size());
      _fields.addAll(foundFields.values());
    }
  }
Пример #2
0
  /**
   * Method for resolving member method information: aggregating all non-static methods and
   * combining annotations (to implement method-annotation inheritance)
   *
   * @param collectIgnored Whether to collect list of ignored methods for later retrieval
   */
  public void resolveMemberMethods(MethodFilter methodFilter, boolean collectIgnored) {
    _memberMethods = new AnnotatedMethodMap();
    AnnotatedMethodMap mixins = new AnnotatedMethodMap();
    // first: methods from the class itself
    _addMemberMethods(_class, methodFilter, _memberMethods, _primaryMixIn, mixins);

    // and then augment these with annotations from super-types:
    for (Class<?> cls : _superTypes) {
      Class<?> mixin = (_mixInResolver == null) ? null : _mixInResolver.findMixInClassFor(cls);
      _addMemberMethods(cls, methodFilter, _memberMethods, mixin, mixins);
    }
    // Special case: mix-ins for Object.class? (to apply to ALL classes)
    if (_mixInResolver != null) {
      Class<?> mixin = _mixInResolver.findMixInClassFor(Object.class);
      if (mixin != null) {
        _addMethodMixIns(methodFilter, _memberMethods, mixin, mixins);
      }
    }

    /* Any unmatched mix-ins? Most likely error cases (not matching
     * any method); but there is one possible real use case:
     * exposing Object#hashCode (alas, Object#getClass can NOT be
     * exposed, see [JACKSON-140])
     */
    if (!mixins.isEmpty()) {
      Iterator<AnnotatedMethod> it = mixins.iterator();
      while (it.hasNext()) {
        AnnotatedMethod mixIn = it.next();
        try {
          Method m = Object.class.getDeclaredMethod(mixIn.getName(), mixIn.getParameterClasses());
          if (m != null) {
            AnnotatedMethod am = _constructMethod(m);
            _addMixOvers(mixIn.getAnnotated(), am, false);
            _memberMethods.add(am);
          }
        } catch (Exception e) {
        }
      }
    }

    /* And last but not least: let's remove all methods that are
     * deemed to be ignorable after all annotations have been
     * properly collapsed.
     */
    Iterator<AnnotatedMethod> it = _memberMethods.iterator();
    while (it.hasNext()) {
      AnnotatedMethod am = it.next();
      if (_annotationIntrospector.isIgnorableMethod(am)) {
        it.remove();
        if (collectIgnored) {
          _ignoredMethods = ArrayBuilders.addToList(_ignoredMethods, am);
        }
      }
    }
  }
 public void setIgnorableProperties(String[] ignorable) {
   _ignorableProperties =
       (ignorable == null || ignorable.length == 0) ? null : ArrayBuilders.arrayToSet(ignorable);
 }