/**
   * Recursively-copies properties from the Object, up the inheritance hierarchy, to the destination
   * Resource.
   *
   * @param type the Type of the object being copied. May be a super-type of the 'from' object.
   * @param from the instance of Object being copied.
   * @param to the destination Resource instance.
   */
  private void copyProperties0(Class<?> type, Object from, Resource to) {
    if (type == null) return;
    if (Resource.class.isAssignableFrom(type)) {
      to.from((Resource) from);
      return;
    }

    Field[] fields = getDeclaredFields(type);

    try {
      for (Field f : fields) {
        if (isIncluded(f)) {
          f.setAccessible(true);
          Object value = f.get(from);

          if (value != null) {
            addProperty(to, f, value);
          }
        }
      }
    } catch (IllegalAccessException e) {
      throw new ResourceException(e);
    }

    copyProperties0(type.getSuperclass(), from, to);
  }
 /**
  * Template method. Sub-classes can override to possibly handle annotations on the field, etc. By
  * default, this method simply adds the property to the resource using the value and the given
  * name of the field.
  *
  * @param to the destination resource.
  * @param f the field to copy.
  * @param value the value of the field.
  */
 protected void addProperty(Resource to, Field f, Object value) {
   to.addProperty(f.getName(), value);
 }