反向ToStringBuilder:将字符串转换为对象 [英] Reverse ToStringBuilder : convert string to object

查看:162
本文介绍了反向ToStringBuilder:将字符串转换为对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 ToStringBuilder 回到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 - 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:将字符串转换为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆