首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java:将元帅解封为.properties格式?

Java:将元帅解封为.properties格式?
EN

Stack Overflow用户
提问于 2012-09-29 05:37:48
回答 1查看 264关注 0票数 0

注意,这与封送属性对象无关。

我想要一种房产格式。示例:

代码语言:javascript
复制
class Foo { String a = "aaa"; Item i = new Item(); }
class Item { String val = "Value"; }

marshall( new 

转到

代码语言:javascript
复制
a = Hello
i.value = Value

我知道这种方法有其局限性,但没关系。

,有这样的东西吗?

如果没有,是否有一些简单的表达式语言库,既可以在对象树中查询对象,也可以识别“字符串键”?

我查过BeanUtils了-什么都没有。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-29 06:47:33

为此,可以使用objectprops(http://code.google.com/p/objectprops/):

代码语言:javascript
复制
ObjectPropertiesStore store = new ObjectPropertiesStore();

// write the object to the store        
store.writeObject(new Foo());

// let's get the Properties object and print the contents to System.out
Properties properties = store.getDatabase();
properties.store( System.out, "My test");

或者,您可以使用ReflectionToStringBuilder of commons轻松地实现这一点,并传递您自己实现的自定义ToStringStyle,并将得到的字符串加载到属性对象中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12650245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档