|
11 | 11 | import java.lang.reflect.Field; |
12 | 12 | import java.lang.reflect.Modifier; |
13 | 13 | import java.util.Arrays; |
14 | | -import java.util.HashMap; |
15 | | -import java.util.Map; |
16 | 14 | import java.util.Optional; |
17 | | -import java.util.function.Function; |
18 | 15 |
|
19 | 16 | /** |
20 | 17 | * Utility class for resolving JSON files. |
21 | 18 | */ |
22 | 19 | @Slf4j |
23 | 20 | public class ReflectionUtils { |
24 | | - private static final Map<Class<?>, Function<String, Object>> propertyTypeParsers = new HashMap<>(); |
25 | | - |
26 | 21 | private ReflectionUtils() { |
27 | 22 | } |
28 | 23 |
|
@@ -80,36 +75,7 @@ private static Field findDeclaredField(Class<?> cl, String name) throws NoSuchFi |
80 | 75 | } |
81 | 76 |
|
82 | 77 | /** |
83 | | - * Gets a mapping of properties and their type, recursively for the given |
84 | | - * type. |
85 | | - * |
86 | | - * @param parentPropertyName The root property name to append child field |
87 | | - * names to. This is null for the base case. |
88 | | - * @param parentClass The class to search for properties in. |
89 | | - * @return The map of properties and their types. |
90 | | - * @throws IllegalAccessException If a field cannot have its value obtained. |
91 | | - */ |
92 | | - public static @NotNull Map<String, Class<?>> getFields(@NotNull String parentPropertyName, @NotNull Class<?> parentClass) throws IllegalAccessException { |
93 | | - Map<String, Class<?>> fieldsMap = new HashMap<>(); |
94 | | - for (Field field : parentClass.getDeclaredFields()) { |
95 | | - // Skip transient fields. |
96 | | - if (Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) continue; |
97 | | - field.setAccessible(true); |
98 | | - String fieldPropertyName = parentPropertyName == null ? field.getName() : parentPropertyName + "." + field.getName(); |
99 | | - // Check if the field represents a "leaf" property, one which does not have any children. |
100 | | - if (propertyTypeParsers.containsKey(field.getType())) { |
101 | | - fieldsMap.put(fieldPropertyName, field.getType()); |
102 | | - } else { |
103 | | - Map<String, Class<?>> childFieldsMap = getFields(fieldPropertyName, field.getType()); |
104 | | - fieldsMap.putAll(childFieldsMap); |
105 | | - } |
106 | | - } |
107 | | - return fieldsMap; |
108 | | - } |
109 | | - |
110 | | - /** |
111 | | - * Sets the value of a field to a certain value, using {@link ReflectionUtils#propertyTypeParsers} |
112 | | - * to try and parse the correct value. |
| 78 | + * Sets the value of a field to a new value. |
113 | 79 | * |
114 | 80 | * @param field The field to set. |
115 | 81 | * @param parent The object whose property value to set. |
|
0 commit comments