FasterXML / FasterXML/jackson-dataformat-xml

Using `@XmlAttribute` for property with non-scalar type prevents serialization as attribute for other properties

Ouverte
#128 5 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
has-failing-test
Langage dominant
Java
Étoiles
631
Forks
246
Merge moyen
7 j 9 h
PR mergées (30 j)
13

Description

Look at the last line of this class.
Incorrect using `@XmlAttribute` for a bean serialization breaks a serialization of other properties.
I excepted to see an error or bean value as an attribute value.

``` java
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

public class Bug2 {

@XmlRootElement(name = "bean")
public static class Bean {

}

@XmlRootElement(name = "root")
public static class Container {
@XmlAttribute(name = "start")
public String start;

@XmlAttribute(name = "bean")
public Bean bean;

@XmlAttribute(name = "end")
public String end;
}

public static void main(String[] args) throws JsonProcessingException {
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.registerModule(new JaxbAnnotationModule());
xmlMapper.registerModule(new JacksonXmlModule());

Container container = new Container();
container.start = "!start";
container.end = "!end";
System.out.println(xmlMapper.writeValueAsString(container)); // print

Bean bean = new Bean();
container.bean = bean;
System.out.println(xmlMapper.writeValueAsString(container)); // print !end
}
}

```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.