Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9162809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:18:05+00:00 2026-06-17T14:18:05+00:00

I have the following code in one of my classes: @Text(required=false) @ElementListUnion({ @ElementList(required =

  • 0

I have the following code in one of my classes:

@Text(required=false)
@ElementListUnion({
    @ElementList(required = false, inline = true, type = com.company.Child.class, entry="values")
})
public List<Object> valueUnion;

Note that this seems to be the only way to get the framework to work with elements that contain both children and text. This works great when text is present and the elementlist contains elements as well, and produces the following xml:

<parent>
    <values>val 1</values>
    <values>val 2</values>
    some text
</parent>

However, sometimes the element list contains no elements, with only the text being present (meaning the valueUnion List only contains one element, the string of text). This however, results in the following XML:

<parent>
    <values />
    some text
</parent>

And herein lies the problem, as this causes the server to choke over the empty <values /> tag. Unfortunately I do not have control over the code on the server, and I am looking for a way to force Simple to ignore the empty tag if the elementlist contains no elements.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:18:06+00:00Added an answer on June 17, 2026 at 2:18 pm

    I have a workaround for you. Its not beautiful, but the concept can help you here.
    Instead of element-annotations you can use a custom Converter which serializes your Objects.

    • Example Class:

    (Contains the list, the text and other elements you need)

    @Root(name="parent")
    @Convert(ExampleConverter.class)
    public class Example
    {
        private String text; // Save the text you want to set ('some text' in your code)
        private List<Object> valueUnion;
    
        // Constructor + getter / setter
    }
    

    Actually you only need the @Convert(ExampleConverter.class) and @Root Annotations here, since the serialization is done in your own converter (ExampleConverter).

    • ExampleConverter Class:

    (Serialize / Deserialize your Object here)

    public class ExampleConverter implements Converter
    {
        @Override
        public Object read(InputNode node) throws Exception
        {
            /* TODO: Deserialize your class here (if required). */
            throw new UnsupportedOperationException("Not supported yet.");
        }
    
    
        @Override
        public void write(OutputNode node, Object value) throws Exception
        {
            final Example val = (Example) value;
            final List<Object> l = val.getValueUnion();
    
            if( !l.isEmpty() ) // if there are elements, insert their nodes
            {
                for( Object obj : l )
                {
                    node.getChild("values").setValue(obj.toString());
                }
            }
            else
            {
                node.getChild("values").setValue(""); // this creates <values></values> if list is empty
            }
            node.setValue(val.getText()); // Set the text (1)
        } 
    }
    

    (1): This will set your text even if there are some other elements. However this solution may break your formating; the text and the closing tag will be on the same line. You can solve this by inserting a new line.

    • Usage:

    Create a serializer, et your strategy and write / read

    Serializer ser = new Persister(new AnnotationStrategy()); // 'AnnotationStrategy is important here!
    ser.write(...); // write / read
    
    • Examples:

    With elements in the list:

    Example t = new Example();
    t.setText("abc"); // Set the text
    t.getValueUnion().add("value1"); // Add some elements to list
    t.getValueUnion().add("value2");
    
    Serializer ser = new Persister(new AnnotationStrategy());
    ser.write(t, f); // 'f' is the file to write
    

    Output:

    <parent>
       <values>value1</values>
       <values>value2</values>abc</parent>
    

    Without elements in the list:

    Example t = new Example();
    t.setText("abc"); // Set the text
    
    Serializer ser = new Persister(new AnnotationStrategy());
    ser.write(t, f); // 'f' is the file to write
    

    Output:

    <parent>
       <values></values>abc</parent>
    

    Please notice the formating “problem” as said before!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in one of my classes along with checks when
i have the following code part in one of my classes: $l = new
I have the following code in one cpp file which is part of a
I have the following code in one of my Rails 3 application views: <ul>
I have the following code in one of our projects webpages: XmlDocument xDoc =
Using linkedin-j , I have the following code in one part of my application
I have the following code snippet: enum { one } x; enum { two
In Scala IDE I have the following code: package pkg.one object S { class
I have the following code and everytime I click on one of the markers,
I have the following code which swaps out one divs innerHTML for the others

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.