Reputation: 3
I'm trying to POST a entity to a REST endpoint with Retrofit. I have no control over the endpoint code.
The entity consists of a list of objects of another entity.
public class DemoEntity {
@ElementList(inline = true);
private List<SubEntry> entries;
}
@Root(name = "subEntry")
public class SubEntry {
@Attribute(name = "attr")
private String attribute;
}
I want the resulting xml to look like this
<?xml version="1.0"...>
<subEntry attr="a" />
<subEntry attr="b" />
<subEntry attr="c" />
But the serializer always includes the root element of DemoEntity.
<?xml version="1.0"... ?>
<DemoEntity>
<subEntry attr="a" />
<subEntry attr="b" />
<subEntry attr="c" />
</DemoEntity>
Is there any way to circumvent the default (and correct) behaviour to "ignore" the root element?
Upvotes: 0
Views: 125
Reputation: 5892
The serializer seems to follow the official spec for XML. You can check that following SO answer. So basically for a well formed XML and compliant with the standard you need a root element.
What I can suggest is, if your really need to jump over the standard, you can:
I would suggest firstly if the endpoint you are accessing really uses a non-compliant xml, just before going with a harder solution.
Upvotes: 1