FasterXML / FasterXML/jackson-dataformat-xml

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

未關閉
#128 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
has-failing-test
主要語言
Java
星號
631
分支
246
平均合併
7 天 9 小時
30 天內合併 PR
13

描述

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

```

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。