@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); } } }
@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()); } }
@Override public final void fromMap(Map<String, ?> map) { from(map, fields()); }
@Override public final void from(Object source, int... fieldIndexes) { from(source, fields(fieldIndexes)); }
@Override public final void from(Object source, String... fieldNames) { from(source, fields(fieldNames)); }