简体   繁体   English

简单的XML框架:序列化时elementlist中的字符串没有名称空间前缀

[英]Simple XML Framework: Strings in elementlist not having namespace prefix when serializing

I have this code: 我有以下代码:

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

which has an ancester: 它有一个祖先:

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

and it generates: 它生成:

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

when I'm expecting: 当我期望:

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

Is is possible to achieve this? 有可能实现这一目标吗?

Did you try to do this: 您是否尝试这样做:

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

UPDATE UPDATE
As doppelganger has written in the comments is not possible to extend String (it is final), so he has proposed this (correct) solution: 正如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;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM