Comment sérialiser objet java comme attribut xml avec jackson?
est-il un moyen de sérialiser un java var (ex int) par l'intermédiaire de michael jackson comme un attribut xml?
Je ne peux trouver aucune spezific jackson ou json annotations (@XmlAttribute
@javax.xml.bind.annotation.XmlAttribute) pour s'en rendre compte.
par exemple
public class Point {
private int x, y, z;
public Point(final int x, final int y, final int z) {
this.x = x;
this.y = y;
this.z = z;
}
@javax.xml.bind.annotation.XmlAttribute
public int getX() {
return x;
}
...
}
Ce que je veux:
<point x="100" y="100" z="100"/>
mais tout ce que j'ai est:
<point>
<x>100</x>
<y>100</y>
<z>100</z>
</point>
Est-il un moyen d'obtenir les attributs au lieu d'éléments?
Merci pour l'aide!
Il n'y a pas de problème avec le type int. Ce que j'ai jamais essayé, je viens de recevoir les éléments xml plutôt que des attributs.
OriginalL'auteur Divine | 2013-02-05
Vous devez vous connecter pour publier un commentaire.
Bon j'ai trouvé une solution.
Il n'est pas nécessaire d'inscrire un AnnotaionIntrospector si vous utilisez jackson-format xml
La BALISE manquante a été
@JacksonXmlProperty(isAttribute=true)
donc il suffit de changer le fonceur:
et il fonctionne très bien. Il suffit de suivre cette procédure:
https://github.com/FasterXML/jackson-dataformat-xml
OriginalL'auteur Divine
Avez-vous enregistré JaxbAnnotationIntrospector?
OriginalL'auteur Anthony Accioly