Hi,

I'm having problems parsing/serializing classes to XML that have
values stored in a generic container, such as for example Optional<T>
( 
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Optional.html
). When the container is empty (e.g. !Optional.isPresent), i don't
want the field to be serialized at all.

For example, a field
 class Bar {
    Optional<String> myField1;
    String myField2;
  }
would either serialize to:
   <bar>
      <myField1>Some string</myField1>
      <myField2>Some other string</myField2>
    <bar>
or to
   <bar>
        <myField2>Some other string</myField2>
   </bar>
depending on whether myField1 contains a value or not.

Concretely, I have 2 problems:
- If I write a convertor for the Optional type, I don't know what the
right way is to marshal the containing type (basically, I just want to
delegate the serializing further to the default serialization
behavior)
- A convertor doesn't control the generated tags, so I can't omit
fields from the convertor. I also can't write a mapper, since the
condition on whether to omit an element is based on the actual value
of the object, and as far as i can tell, the check is based on static
type information only. This problem is less crucial than the previous
one, since I suppose i can work around this by writing a filter to
strip empty elements from XML.

Any suggestions?

thanks!
Remko

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to