Closed mbjelac closed 9 years ago
Again, great idea!
Me again asking a question :) Isn't this what you actually want?
BeanUtil.populateBean(httpConfig, (Map) properties.get("http"));
You see, i kind of like this better then this:
BeanUtil.populateBean(httpConfig, properties, "http");
because map.get("name") can be anything and not always a map; and its therefore kind of vague. Moreover, you can do something like:
Map values = (Map) BeanUtil.getProperty(properties, "http.inner");
BeanUtil.populateBean(httpConfigInner, values);
I know it is not one liner, but the functionality is there. Wdyt?
aha, i wasn't aware that BeanUtil.getProperty
does that - so basically it extracts a sub-map from a map based on the prefix? if you do BeanUtil.getProperty(properties, "http.inner");
do the keys in the resulting map have the http.inner
prefix?
Oopps sorry, that is not true what i've written.... I mixed this with the Props tool. Give me a sec to write what I ment :)))
Ok here am I again, sorry for confusion.
BeanUtil
is not aware of property names; so in its world it is the same if you have property named "foobar"
or "foo.bar"
- this is all the same to it.
However, this seems to be task for Jodd Props that is properties on steroids. Please give me some time to explore the options, as we already have something almost like you need :)
Ok, after last commits, you can do this like:
Props props = new Props();
props.load(data); // load props from Properties or directly from a file
Map innerMap = props.innerMap("http");
HttpConfig httpConfig = new HttpConfig();
BeanCopy.fromMap(innerMap).toBean(httpConfig).copy();
As said above, BeanUtil
is unaware of the java properties syntax. For this we do have the Jodd Props tool - the powerful properties replacement. You may use it instead of regular java properties.
I hope you understand and that we can close this issue now ;)
When a single properties map contains multiple "sections", for example a
http
sectionit would be handy to be able to populate a bean with a section, for the above example, a
HttpConfig
beancould be populated with
BeanUtils.populate(httpConfig, properties, "http")
.Currently the only way to populate such beans is to create a "root" property bean