@Test public void testMap() { String name = "hmily.yml"; Map<String, Object> map = new HashMap<>(); map.put("hmily.map.userName", "sixh"); map.put("hmily.map.passWord", 123456); PropertyKeySource<?> propertySource = new MapPropertyKeySource(name, map); ConfigPropertySource configPropertySource = new DefaultConfigPropertySource<>(propertySource, PropertyKeyParse.INSTANCE); Binder binder = Binder.of(configPropertySource); BindData<MapPojo> data = BindData.of(DataType.of(MapPojo.class), MapPojo::new); MapPojo bind = binder.bind("hmily", data); Assert.assertEquals(bind.getMap().get("userName"), map.get("hmily.map.userName")); Assert.assertEquals(bind.getMap().get("passWord"), map.get("hmily.map.passWord")); System.out.println(bind); }
@Override public Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder) { Map<Object, Object> map = new HashMap<>(16); boolean hasDescendants = env.getSource().containsDescendantOf(propertyName); if (!hasDescendants) { new EntryBinder(propertyName, target, env, elementBinder).bindEntries(env.getSource(), map); } return map.isEmpty() ? null : map; }
MapBinder extends AggregateBinder<Map<Object, Object>> { @Override public Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder) { Map<Object, Object> map = new HashMap<>(16); boolean hasDescendants = env.getSource().containsDescendantOf(propertyName); if (!hasDescendants) { new EntryBinder(propertyName, target, env, elementBinder).bindEntries(env.getSource(), map); } return map.isEmpty() ? null : map; } }
MapBinder extends AggregateBinder<Map<Object, Object>> { @Override public Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder) { Map<Object, Object> map = new HashMap<>(16); boolean hasDescendants = env.getSource().containsDescendantOf(propertyName); if (!hasDescendants) { new EntryBinder(propertyName, target, env, elementBinder).bindEntries(env.getSource(), map); } return map.isEmpty() ? null : map; } MapBinder(final Binder.Env env); }
MapBinder extends AggregateBinder<Map<Object, Object>> { @Override public Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder) { Map<Object, Object> map = new HashMap<>(16); boolean hasDescendants = env.getSource().containsDescendantOf(propertyName); if (!hasDescendants) { new EntryBinder(propertyName, target, env, elementBinder).bindEntries(env.getSource(), map); } return map.isEmpty() ? null : map; } MapBinder(final Binder.Env env); @Override Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder); @Override Object merge(final Supplier<?> targetValue, final Map<Object, Object> object); @Override boolean isAllowRecursiveBinding(final Binder.Env source); }
MapBinder extends AggregateBinder<Map<Object, Object>> { @Override public Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder) { Map<Object, Object> map = new HashMap<>(16); boolean hasDescendants = env.getSource().containsDescendantOf(propertyName); if (!hasDescendants) { new EntryBinder(propertyName, target, env, elementBinder).bindEntries(env.getSource(), map); } return map.isEmpty() ? null : map; } MapBinder(final Binder.Env env); @Override Object bind(final PropertyName propertyName, final BindData<?> target, final Binder.Env env, final AggregateElementBinder elementBinder); @Override Object merge(final Supplier<?> targetValue, final Map<Object, Object> object); @Override boolean isAllowRecursiveBinding(final Binder.Env source);  }