| 52 | } |
| 53 | |
| 54 | @SneakyThrows |
| 55 | public static Map<String, Object> toMap(@NonNull Object object) { |
| 56 | val result = new HashMap<String, Object>(); |
| 57 | val type = object.getClass(); |
| 58 | for (val field : type.getDeclaredFields()) { |
| 59 | val modifiers = field.getModifiers(); |
| 60 | if (isFinal(modifiers) || isStatic(modifiers)) { |
| 61 | continue; |
| 62 | } |
| 63 | field.setAccessible(true); |
| 64 | |
| 65 | val fieldValue = field.get(object); |
| 66 | if (fieldValue == null) { |
| 67 | continue; |
| 68 | } |
| 69 | |
| 70 | val propertyKey = |
| 71 | field.isAnnotationPresent(FormProperty.class) |
| 72 | ? field.getAnnotation(FormProperty.class).value() |
| 73 | : field.getName(); |
| 74 | |
| 75 | result.put(propertyKey, fieldValue); |
| 76 | } |
| 77 | return result; |
| 78 | } |
| 79 | |
| 80 | private PojoUtil() throws UnexpectedException { |
| 81 | throw new UnexpectedException("It is not allowed to instantiate this class"); |