[英]Java: Marshal unmarshal to .properties format?
请注意,这与封送属性对象无关。
我想编组为属性格式。 例:
class Foo { String a = "aaa"; Item i = new Item(); }
class Item { String val = "Value"; }
marshall( new
进入
a = Hello
i.value = Value
我知道这种方法有局限性,但是没关系。
这些路线上有东西吗?
如果不是,是否有一些简单的表达语言lib可以同时执行-查询对象并在对象树中标识“字符串键”?
我检查了BeanUtils-那里什么都没有。
您可以为此使用objectprops( http://code.google.com/p/objectprops/ ):
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");
或者,您可以使用commons-lang的ReflectionToStringBuilder并通过传递您自己实现的自定义ToStringStyle轻松地实现此目的,并将结果字符串加载到Properties对象中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.