FasterXML / FasterXML/jackson-dataformat-xml

XML Serialization + JsonAnyGetter as attributes

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

描述

Hi there,

I'm having some issues with the serialization of dynamic data as attributes of an XML element.
Note: Tested on both version 2.9.6 and 2.9.7

Given the Object:
```java
@JacksonXmlRootElement(localName = "metadata")
private static class ObjectWithAttributes {

@JsonAnyGetter
public Map getData() {
Map map = new HashMap<>();
map.put("a", "some value");
map.put("b", "and another one");
return map;
}
}
```

I was expecting to get the following XML :
```xml

```
but got:
```xml

some value
and another one

```
I tried to fiddle around with some of the annotations available be never got it to serialize the values as attributes.
I even tried to write a custom serializer which worked fine when annotating the class with the ``` @JsonSerialize(using =...) ``` but would results in any other attribute fields to not be serialized :(

I couldn't find any documentations regarding the uses of ``` @JsonAnyGetter ``` to get the values as attributes and not sub elements.

Is this use case not supported by Jackson ?

Thanks in advance,
Best regards.

貢獻指南

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

評估

這個 Issue 還沒有評估資料。

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

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