Xstream - 字符串数组
首先,我不是在寻求解决方案,而是寻求一种思考方式。
我得到了一些需要序列化以便稍后查看的数据...我知道该怎么做..但是字段名称是问题...
数据结构包含:(
Name of the Field
CoordX
CoordY
Value
大约有.. 20 个不同的字段。我需要检查 biiiggggg 字符串日志...)
我可以使用单个 String[][] 或多个 String[] ...正如我所说..问题是它在 XML 上的显示方式...
如果我执行单个数组列表多维 -> [][] 我得到了这个
<teste>
<string-array>
<string>fieldName</string>
<string>x</string>
<string>y</string>
<string>value</string>
</string-array>
<string-array>
<string>fieldName</string>
<string>x</string>
<string>y</string>
<string>value</string>
</string-array>
</teste>
如果我执行单个字符串[],我可以将字符串的名称作为字段名称
<Fieldname>
<string>X</string>
<string>y</string>
<string>Value</string>
</Fieldname>
我看到正常的别名适用于所有字段(@XStreamImplicit(itemFieldName =“part”))并且不能解决我的问题..
如果在另一边进行反序列化时,按行检查日志而不按字段检查日志(我知道第1行是字段名称,第2行是x..等),那么它可能毫无价值。
所以..你们觉得怎么样?
First things first, I'm no asking for a solution but a way to think.
I got some data that I need to serialize to check out later... I know how to do it.. but the fields names are the problem...
The data structure contains:
Name of the Field
CoordX
CoordY
Value
(There are like.. 20 different fields. I need to check a biiiggggg string log...)
I could use a single String[][] or several Strings[] ... as I said.. the problem is how it appears on the XML...
If I do a single arraylist multidimensional -> [][] I got this
<teste>
<string-array>
<string>fieldName</string>
<string>x</string>
<string>y</string>
<string>value</string>
</string-array>
<string-array>
<string>fieldName</string>
<string>x</string>
<string>y</string>
<string>value</string>
</string-array>
</teste>
And if I do a single string[] I can put the name of the String as the field name
<Fieldname>
<string>X</string>
<string>y</string>
<string>Value</string>
</Fieldname>
I saw that normal alias is for ALL fields (@XStreamImplicit(itemFieldName="part")) and that don't solve my problem..
It could be worthless if on the other side when I do deserialization, check the log by line and no by field (I know line 1 is field name, line 2 is x..etc)..
So.. what do you guys think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通常根据“字段”的内容设计序列化。假设您的名称和值字段相对较小,您当然可以将它们序列化
,如果值很长,那么您不想将其序列化为属性,而是作为常规字段值,如下所示:
您可以使用XStream 像这样:
您在其中定义容器和字段,如下所示:
程序给出以下输出:
希望这会有所帮助。
I usually design serialization depending on the contents of my "fields". Say that your name and value fields are relatively small, you could serialize them as
of course, if value is long, then you don't want to serialize it as attribute, but as a regular field value like so:
You can achieve this using XStream like so:
where you define your Container and Field like so:
The program gives this output:
Hope this helps.