BeanAdapter extends AbstractMap<String, Object> { @Override public Object get(Object key) { if (key == null) { throw new IllegalArgumentException(); } Method method = accessors.get(key); Object value; if (method != null) { try { value = adapt(method.invoke(bean), accessorCache); } catch (InvocationTargetException | IllegalAccessException exception) { throw new RuntimeException(exception); } } else { value = null; } return value; } BeanAdapter(Object bean); private  BeanAdapter(Object bean, HashMap<Class<?>, HashMap<String, Method>> accessorCache); @Override Object get(Object key); @Override Set<Entry<String, Object>> entrySet(); @SuppressWarnings("unchecked") static T adapt(Object value); @SuppressWarnings("unchecked") static T adapt(Object value, Type type); static List<E> adaptList(List<?> list, Type elementType); static Map<K, V> adaptMap(Map<K, ?> map, Type valueType); @SuppressWarnings("unchecked") static V valueAt(Object root, String path); static String describe(Type type, Map<Class<?>, String> structures);  }
@Test public void testBeanAdapter1() throws MalformedURLException { Map<String, ?> expected = mapOf( entry("i", 1), entry("long", 2L), entry("double", 4.0), entry("string", "abc"), entry("bigInteger", BigInteger.valueOf(8192L)), entry("dayOfWeek", DayOfWeek.values()[3]), entry("date", new Date(0)), entry("localDate", LocalDate.parse("2018-06-28")), entry("localTime", LocalTime.parse("10:45")), entry("localDateTime", LocalDateTime.parse("2018-06-28T10:45")), entry("URL", new URL("http: entry("nestedBean", mapOf( entry("flag", true) )), entry("list", listOf(2L, 4.0, mapOf( entry("flag", true) ))), entry("testArrayList", listOf()), entry("nestedBeanList", listOf(mapOf( entry("flag", false) ))), entry("map", mapOf( entry("long", 2L), entry("double", 4.0), entry("nestedBean", mapOf( entry("flag", true) ))) ), entry("testHashMap", mapOf()), entry("nestedBeanMap", mapOf( entry("nestedBean", mapOf( entry("flag", false) ))) ) ); Map<String, Object> actual = new BeanAdapter(new TestBean()); assertEquals(expected, actual); assertNull(actual.get("ignored")); }