gpt4 book ai didi

java - 简单的 XML 框架 : Strings in elementlist not having namespace prefix when serializing

转载 作者:行者123 更新时间:2023-11-29 20:56:30 24 4
gpt4 key购买 nike

我有这个代码:

@ElementList(name = "Telefono")
@Namespace(reference = "efactura")
protected List<String> telefono;

它有一个祖先:

@Namespace(prefix = "ns2", reference = "efactura")
public class CFEDefType {

它生成:

 <ns2:Telefono class="java.util.Arrays$ArrayList">
<string>12341234</string>
<string>0303456</string>
</ns2:Telefono>

当我期待时:

 <ns2:Telefono class="java.util.Arrays$ArrayList">
<ns2:string>12341234</string>
<ns2:string>0303456</string>
</ns2:Telefono>

这有可能实现吗?

最佳答案

你试过这样做吗:

@Namespace(prefix = "ns2")
public final class Ns2String extends String {}

更新
由于 doppelganger 在评论中写道不可能扩展 String(这是最终的),所以他提出了这个(正确的)解决方案:

@Root(name="string")
@Namespace(reference = "efactura")
public static class Ns2String {
@Text
private String string = null;
public Ns2String(String string) {
this.string = string;
}
public String getString() {
return string;
}
public void setString(String string) {
this.string = string;
}
}

关于java - 简单的 XML 框架 : Strings in elementlist not having namespace prefix when serializing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27548475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com