Doppelganger
Doppelganger

Reputation: 20835

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?

Upvotes: 1

Views: 562

Answers (1)

spacifici
spacifici

Reputation: 2186

Did you try to do this:

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

UPDATE
As doppelganger has written in the comments is not possible to extend String (it is final), so he has proposed this (correct) solution:

@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;
  }
}

Upvotes: 2

Related Questions