예제 #1
0
  protected boolean isVisible(JsonAutoDetect.Visibility visibility, DecoratedElement element) {
    if (visibility != null) {
      switch (visibility) {
        case ANY:
          return true;
        case NONE:
          return false;
        case NON_PRIVATE:
          return !element.getModifiers().contains(Modifier.PRIVATE);
        case PROTECTED_AND_PUBLIC:
          return element.getModifiers().contains(Modifier.PROTECTED)
              || element.getModifiers().contains(Modifier.PUBLIC);
      }
    }

    return element.getModifiers().contains(Modifier.PUBLIC);
  }
예제 #2
0
  /**
   * Whether to accept the given member declaration as an accessor.
   *
   * @param element The declaration to filter.
   * @return Whether to accept the given member declaration as an accessor.
   */
  public boolean accept(DecoratedElement<?> element) {
    if (element.getAnnotation(JsonIgnore.class) != null) {
      return false;
    }

    if (element.getAnnotation(JsonProperty.class) != null) {
      // if there's an explicit json property annotation, we'll include it.
      return true;
    }

    if (this.honorJaxb) {
      if (element.getAnnotation(XmlTransient.class) != null) {
        return false;
      }

      for (String annotationName : element.getAnnotations().keySet()) {
        if (annotationName.startsWith("javax.xml.bind.annotation")) {
          // if the property has an explicit annotation, we'll include it.
          return true;
        }
      }
    }

    String name = element.getSimpleName().toString();
    if ("".equals(name)) {
      return false;
    }

    if (this.propertiesToIgnore.contains(name)) {
      return false;
    }

    if (element instanceof PropertyElement) {
      PropertyElement property = ((PropertyElement) element);

      DecoratedExecutableElement getter = property.getGetter();
      if (getter == null) {
        // needs a getter.
        return false;
      }

      if (!isVisible(findGetterVisibility(getter), getter)) {
        return false;
      }

      DecoratedExecutableElement setter = property.getSetter();
      if (setter != null && !isVisible(findSetterVisibility(), setter)) {
        return false;
      }

      return true;
    } else if (element instanceof DecoratedVariableElement) {

      if (!isVisible(findFieldVisibility(), element)) {
        return false;
      }

      if (element.isStatic() || element.isTransient()) {
        return false;
      }

      return true;
    }

    return false;
  }