FasterXML / FasterXML/jackson-dataformat-xml

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

Aperta
#128 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
has-failing-test
Lingua principale
Java
Stelle
631
Fork
246
Merge medio
7g 9h
PR unite (30g)
13

Descrizione

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

```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.