I'm using springfox 3.0.0 and my XML Swagger looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Foo>
<anotherBar>
<MyStr>string</MyStr>
</anotherBar>
<bar>
<MyStr>string</MyStr>
</bar>
<MyDate>2021-10-08T16:08:57.795Z</MyDate>
</Foo>
Here is what I would like:
<?xml version="1.0" encoding="UTF-8"?>
<Foo>
<AnotherBar>
<MyStr>string</MyStr>
</AnotherBar>
<Bar>
<MyStr>string</MyStr>
</Bar>
<MyDate>2021-10-08T16:08:57.795Z</MyDate>
</Foo>
As you can see, MyStr
and MyDate
are displayed correctly in the XML but not bar
and anotherBar
without the uppercase.
I don't know why the @XmlElement
annotation is ignored by Springfox for nested objects only. But it works great with String
or Instant
.
Here is my Foo
class:
@XmlRootElement(name = "Foo")
public class Foo {
@XmlElement(name = "MyDate")
private Instant myDate;
@XmlElement(name = "Bar")
private Bar bar;
@XmlElement(name = "AnotherBar")
private Bar anotherBar;
// Getter / Setter...
}
And here is my Bar
class:
public class Bar {
@XmlElement(name = "MyStr")
private String myStr;
// Getter / Setter ...
}
Here is my XmlMapper
config:
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.registerModule(new JaxbAnnotationModule());
I already tried to replace @XmlElement
with @JacksonXmlProperty
but it's the same result.
I found also this answer https://stackoverflow.com/a/64562167 but I don't want to use @JsonProperty
since I need the JSON from Swagger to use attributes name.
Do you know why @XmlElement
is ignored by Springfox in this case only?