diff --git a/src/main/java/org/cobbzilla/util/reflect/ReflectionUtil.java b/src/main/java/org/cobbzilla/util/reflect/ReflectionUtil.java index 42f4e86..67649e7 100644 --- a/src/main/java/org/cobbzilla/util/reflect/ReflectionUtil.java +++ b/src/main/java/org/cobbzilla/util/reflect/ReflectionUtil.java @@ -518,12 +518,13 @@ public class ReflectionUtil { * Same as copy(dest, src) but only named fields are copied * @param dest destination object, or a Map * @param src source object + * @param prefix prefix map keys with this String * @param fields only fields with these names will be considered for copying * @param exclude fields with these names will NOT be considered for copying * @param objects must share a type * @return count of fields copied */ - public static int copy (T dest, T src, String[] fields, String[] exclude) { + public static int copy (T dest, T src, String prefix, String[] fields, String[] exclude) { int copyCount = 0; final boolean isMap = dest instanceof Map; try { @@ -598,6 +599,13 @@ public class ReflectionUtil { return copyCount; } + /** + * Same as the other copy, but with no key prefix + */ + public static int copy (T dest, T src, String[] fields, String[] exclude) { + return copy(dest, src, "", fields, exclude); + } + private static boolean isIgnored(T o, String fieldName, Method getter) { Field field = null; try { @@ -702,11 +710,22 @@ public class ReflectionUtil { * @param thing The thing to copy * @return A copy of the object, created using the thing's copy constructor */ - public static Map toMap(Object thing) { return toMap(thing, null, TO_MAP_STANDARD_EXCLUDES); } + public static Map toMap(Object thing) { return toMap(thing, "", null, TO_MAP_STANDARD_EXCLUDES); } - public static Map toMap(Object thing, String[] fields) { return toMap(thing, fields, TO_MAP_STANDARD_EXCLUDES); } + // prefix keys + public static Map toMap(Object thing, String prefix) { return toMap(thing, prefix, null, TO_MAP_STANDARD_EXCLUDES); } + + public static Map toMap(Object thing, String[] fields) { return toMap(thing, "", fields, TO_MAP_STANDARD_EXCLUDES); } + + public static Map toMap(Object thing, String prefix, String[] fields) { + return toMap(thing, prefix, fields, TO_MAP_STANDARD_EXCLUDES); + } public static Map toMap(Object thing, String[] fields, String[] exclude) { + return toMap(thing, "", fields, exclude); + } + + public static Map toMap(Object thing, String prefix, String[] fields, String[] exclude) { final Map map = new HashMap<>(); copy(map, thing, fields, exclude); return map;