FasterXML / FasterXML/jackson-dataformat-xml

Problem trying to generate XML with dynamic list entry tags

未关闭
#400 7 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
jaxb-type-id
主要语言
Java
星标
631
派生
246
平均合并
7 天 9 小时
30 天内合并 PR
13

描述

I am trying to generate a XML payload for an API that uses a XML based query language. I have something similar to the following code:

```java
public class JacksonTest
{

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonSubTypes({
@JsonSubTypes.Type(value = And.class, name = "and"),
@JsonSubTypes.Type(value = Or.class, name = "or"),
@JsonSubTypes.Type(value = EqualTo.class, name = "equalto"),
})
public interface Filter {

}

public static class And implements Filter {
@JacksonXmlElementWrapper(useWrapping = false)
protected List filter;
}

public static class Or implements Filter {
@JacksonXmlElementWrapper(useWrapping = false)
protected List filter;
}

public static class EqualTo implements Filter {
protected String field;
protected String value;
}

@JacksonXmlRootElement(localName = "query")
public static class MyQuery {

@JacksonXmlElementWrapper(useWrapping = false)
protected List filter;

}

public static void main(String[] args) {
MyQuery myQuery = new MyQuery();
myQuery.filter = new ArrayList<>();

EqualTo equalTo = new EqualTo();
equalTo.field = "WHENMODIFIED";
equalTo.value = "05/14/2020 17:09:33";

And and = new And();
and.filter = new ArrayList<>();
and.filter.add(equalTo);

myQuery.filter.add(and);
}

}
```

and the payload I need would be:

```xml




WHENMODIFIED
05/14/2020 17:09:33


```

but the payload I currently get is:

```xml





WHENMODIFIED
05/14/2020 17:09:33



```

I've already looked everywhere but couldn't figure out how I can convince my And entity to skip the `filter` tag.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。