FasterXML / FasterXML/jackson-dataformat-xml
Using `@XmlAttribute` for property with non-scalar type prevents serialization as attribute for other properties
- Vorherrschende Sprache
- Java
- Sterne
- 631
- Forks
- 246
- Ø Merge
- 7 T. 9 Std.
- Gemergte PRs (30 T.)
- 13
Beschreibung
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
}
}
```
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.