Vic
Vic

Reputation: 1888

Simple-framework ignores empty XML elements in list

While deserializing a simple list of strings Simple Framework just ignores empty tags and includes only non-empty values. How can this be fixed?

I want this XML part

<type>
    <inflection></inflection>
    <inflection></inflection>
    <inflection>example</inflection>
    <inflection></inflection>
    <inflection></inflection>
    <inflection></inflection>
    <inflection></inflection>
</type>

to produce an array with 7 elements where the 2nd one equals to 'example' and all others are empty strings or nulls. Instead I just get a one-element list.

My Type class looks like the following (it is a part of bigger hierarchy, therefore it has no @Root annotation):

public class Type {
    ...
    @ElementList(inline = true, entry = "inflection")
    private List<String> inflections = new ArrayList<String>();
    ...
}

Upvotes: 1

Views: 206

Answers (1)

ollo
ollo

Reputation: 25350

You can test if the opposite way of this helps you: How to serialize a null string as a single empty tag?

If not, you can use a Converter like this: Empty entry in ElementList SimpleXML

Upvotes: 1

Related Questions