如果我有一个包含20个字段的类,我需要在每个字段上添加@Element注释吗?有没有一种方法来告诉simple-framework to take all?
发布于 2016-07-27 21:09:45
不需要,您可以使用注释:
Default注释用于指定所有字段或方法都应以默认方式序列化。这基本上允许序列化对象、字段或属性,而不需要对它们进行注释。
除了@Default之外,您仍然可以像@Element一样使用自定义批注
@Root
@Default
public static class Example
{
private int value = 3;
private String string = "abc";
@Element(name = "some-custom-name")
private String customString = "custom";
// ...
}输出:
<example>
<value>3</value>
<string>abc</string>
<some-custom-name>custom</some-custom-name>
</example>https://stackoverflow.com/questions/38571548
复制相似问题