Nico Gallegos
Nico Gallegos

Reputation: 421

How to remove an Element List null on Simpleframework XML

I'm using SimpleFramework in order to create a XML. Everything works fine, expect one "little" thing. When one of my lists are empty, SimpleFramework keekps adding the tag of the list (empty, of course). How can I tell Simpleframework not to add the empty tag when it's null or has size == 0 ?

XML Class:

@Root(name="title")
public class XML {
    @ElementList(name="tags", inline=true, required=false, empty=true)
    @Path("tags")
    private List<Tag> tags;
}

Tag class:

    @Root(name="tag")
    public class Tag {
            @Text
            private String name;
     }

When the list is empty:

Generated output:

<xml>
   <tags/>
   <otherTag>1</otherTag>
   <otherTag>2</otherTag>
</xml>

Expected output:

<xml>
   <otherTag>1</otherTag>
   <otherTag>2</otherTag>
</xml>

Upvotes: 0

Views: 341

Answers (1)

Santhosh Kumar Tekuri
Santhosh Kumar Tekuri

Reputation: 3020

remove Path annotation on tags property and try:

@ElementList(name="tags", inline=true, required=false, empty=true)
//@Path("tags")
private List<Tag> tags;

Upvotes: 1

Related Questions