FasterXML / FasterXML/jackson-dataformat-xml
Using `@XmlAttribute` for property with non-scalar type prevents serialization as attribute for other properties
- Dominant language
- Java
- Stars
- 631
- Forks
- 246
- Avg merge
- 7d 9h
- Merged PRs (30d)
- 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
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.