XStream

omitField() and aliasField() does not get taken into account by SerializableConverter

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.3
  • Component/s: None
  • Labels:
    None

Description

The XStream.omitField() method behaves as expected for ReflectionConverter. However, when an object uses custom serialization (writeObject()) and calls ObjectOutputStream.defaultWriteOut(), the fields are not omitted. This is because SerializableConverter does not take into account these fields.

Example of this can be seen here: http://article.gmane.org/gmane.comp.java.xstream.user/1478

  1. doMarshal_patch.java
    29/Aug/06 2:00 PM
    7 kB
    brien colwell
  2. patch-omitted-inherited-fields.txt
    24/Jul/07 7:37 AM
    8 kB
    Hinse ter Schuur
  3. patch-omitted-inherited-fields-test.txt
    24/Jul/07 7:37 AM
    4 kB
    Hinse ter Schuur

Issue Links

Activity

Hide
Joerg Schaible added a comment -

It also does not honor the new alias mechanism for fields. Now that we have an AbstractReflectionConverter, we can maybe refactore the code even more to support both issues with one code base.

Show
Joerg Schaible added a comment - It also does not honor the new alias mechanism for fields. Now that we have an AbstractReflectionConverter, we can maybe refactore the code even more to support both issues with one code base.
Hide
Joerg Schaible added a comment -

Neither does the JavaBeanConverter ...

Show
Joerg Schaible added a comment - Neither does the JavaBeanConverter ...
Hide
brien colwell added a comment -

This is a quick patch for SerializableConverter

Show
brien colwell added a comment - This is a quick patch for SerializableConverter
Hide
Derrick Kittler added a comment -

I ran into this issue today while trying to be explicit about the XML serialization of one of my domain objects. I, much like this issue states, cannot omit fields from the XStream object, for example:
XStream xs = new XStream();
if(entity instanceof Metadata )

{ xs.omitField(Project.class, "project"); // TODO http://jira.codehaus.org/browse/XSTR-280 //$NON-NLS-1$ xs.omitField(MetadataValue.class, "metadataValues"); // TODO http://jira.codehaus.org/browse/XSTR-280 //$NON-NLS-1$ }

String xml = xs.toXML(entity);

The resulting string will contain the elements <project>...</project> and <metadataValues>...</metadataValues> What I would like is the resulting XML string to not serialize these attributes into XML; rather omit them from the final XML string.

Show
Derrick Kittler added a comment - I ran into this issue today while trying to be explicit about the XML serialization of one of my domain objects. I, much like this issue states, cannot omit fields from the XStream object, for example: XStream xs = new XStream(); if(entity instanceof Metadata ) { xs.omitField(Project.class, "project"); // TODO http://jira.codehaus.org/browse/XSTR-280 //$NON-NLS-1$ xs.omitField(MetadataValue.class, "metadataValues"); // TODO http://jira.codehaus.org/browse/XSTR-280 //$NON-NLS-1$ } String xml = xs.toXML(entity); The resulting string will contain the elements <project>...</project> and <metadataValues>...</metadataValues> What I would like is the resulting XML string to not serialize these attributes into XML; rather omit them from the final XML string.
Hide
Derrick Kittler added a comment -

I compiled the Patch in and it still does not have the proper result .... there is no omission of XML elements when using:
xStream.omitField(MyClass.class, "myClassProperty");

Show
Derrick Kittler added a comment - I compiled the Patch in and it still does not have the proper result .... there is no omission of XML elements when using: xStream.omitField(MyClass.class, "myClassProperty");
Hide
Hinse ter Schuur added a comment -

This is a quick patch for JavaBeanConverter

Show
Hinse ter Schuur added a comment - This is a quick patch for JavaBeanConverter
Hide
Hinse ter Schuur added a comment -

A simple test to check if javabean respects the omitted fields

Show
Hinse ter Schuur added a comment - A simple test to check if javabean respects the omitted fields
Hide
Hinse ter Schuur added a comment -

Modified patch with fixes for inheritance of omitted fields and field aliases

Show
Hinse ter Schuur added a comment - Modified patch with fixes for inheritance of omitted fields and field aliases
Hide
Joerg Schaible added a comment -

The patch for the JavaBeanConverter has been applied.

Show
Joerg Schaible added a comment - The patch for the JavaBeanConverter has been applied.
Hide
Joerg Schaible added a comment -

Alias and omit field is now also respected by the SerializableConverter.

Show
Joerg Schaible added a comment - Alias and omit field is now also respected by the SerializableConverter.
Hide
Joerg Schaible added a comment -

Closing issues before next release.

Show
Joerg Schaible added a comment - Closing issues before next release.

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: