Пример #1
0
  @Override
  public final void from(Object source, Field<?>... f) {
    if (source == null) return;

    // [#1987] Distinguish between various types to load data from
    // Maps are loaded using a {field-name -> value} convention
    if (source instanceof Map) {
      fromMap((Map<String, ?>) source, f);
    }

    // Arrays are loaded through index mapping
    else if (source instanceof Object[]) {
      fromArray((Object[]) source, f);
    }

    // All other types are expected to be POJOs
    else {
      Class<?> type = source.getClass();

      try {
        boolean useAnnotations = hasColumnAnnotations(configuration(), type);

        for (Field<?> field : f) {
          List<java.lang.reflect.Field> members;
          Method method;

          // Annotations are available and present
          if (useAnnotations) {
            members = getAnnotatedMembers(configuration(), type, field.getName());
            method = getAnnotatedGetter(configuration(), type, field.getName());
          }

          // No annotations are present
          else {
            members = getMatchingMembers(configuration(), type, field.getName());
            method = getMatchingGetter(configuration(), type, field.getName());
          }

          // Use only the first applicable method or member
          if (method != null) {
            Utils.setValue(this, field, method.invoke(source));
          } else if (members.size() > 0) {
            from(source, members.get(0), field);
          }
        }
      }

      // All reflection exceptions are intercepted
      catch (Exception e) {
        throw new MappingException("An error ocurred when mapping record from " + type, e);
      }
    }
  }
Пример #2
0
  @Override
  public final void from(Object source) {
    if (source == null) return;

    // [#1987] Distinguish between various types to load data from
    // Maps are loaded using a {field-name -> value} convention
    if (source instanceof Map) {
      fromMap((Map<String, ?>) source);
    }

    // Arrays are loaded through index mapping
    else if (source instanceof Object[]) {
      fromArray((Object[]) source);
    }

    // All other types are expected to be POJOs
    else {
      from(source, fields());
    }
  }
Пример #3
0
 @Override
 public final void fromArray(Object[] array, int... fieldIndexes) {
   fromArray(array, fields(fieldIndexes));
 }
Пример #4
0
 @Override
 public final void fromArray(Object[] array, String... fieldNames) {
   fromArray(array, fields(fieldNames));
 }
Пример #5
0
 @Override
 public final void fromArray(Object... array) {
   fromArray(array, fields());
 }