Vous affichez l'annotation sur le champ, mais JAXB utilise l'accès par propriété (méthode getter/setter) par défaut. Avez-vous changé l'accès par défaut de JAXB? Essayez de mettre l'annotation sur la méthode getter à la place.
Edit: Puisque vous semblez avoir du mal, voici un exemple exécutable:
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.*;
import java.io.StringWriter;
public static void main(String[] args) throws Exception {
Foo foo = new Foo("my attribute value", "my element value");
Marshaller marshaller = JAXBContext.newInstance(Foo.class).createMarshaller();
StringWriter stringWriter = new StringWriter();
marshaller.marshal(foo, stringWriter);
System.out.println(stringWriter);
}
@XmlRootElement
static class Foo {
private String anAttribute;
private String anElement;
Foo() {}
public Foo(String anAttribute, String anElement) {
this.anAttribute = anAttribute;
this.anElement = anElement;
}
@XmlAttribute
public String getAnAttribute() { return anAttribute; }
@XmlElement
public String getAnElement() { return anElement; }
}
sortie (formaté):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<foo anAttribute="my attribute value">
<anElement>my element value</anElement>
</foo>
Je l'ai essayé comme ceci: @XmlAttribute public String getDomain() { domaine de retour; } ne fonctionne pas – Starbax
Mise à jour ma réponse avec un exemple de travail. –
J'ai mis à jour mon message, il y a plus de code maintenant – Starbax