问题描述
有没有办法从回到java对象?
Is there a way to convert my output from ToStringBuilder back to java object?
我正在寻找一种简单的方法来表示可读文本文件中的Java对象,并能够在字符串和对象之间来回转换。
I am looking for an easy way to represent a Java object in readable text file and being able to convert back and forth between string and object.
谢谢,
推荐答案
您必须定义严格格式并使用解析器跟随它。有两种可接受的格式:
You must define a strict format and follow it with a parser. There are two accepted formats:
- XML - 您可以使用
- JSON - 使用或
- XML - you can use
java.beans.XMLEncoder
- JSON - use Jackson or gson
如果您不选择这些格式,您将必须自己处理解析。
If you don't choose these formats you will have to handle the parsing yourself.
ToStringBuilder
似乎没有相反的反向。此外,为此目的使用此字符串表示是错误的 - 它仅用于调试。
The ToStringBuilder
does not seem to have a reverse equivalent. Furthermore it is wrong to use this string representation for such purposes - it is meant only for debug.
这篇关于反向ToStringBuilder:将字符串转换为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!