Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Not A Bug
-
Affects Version/s: 1.3.1
-
Fix Version/s: None
-
Component/s: Annotations
-
Labels:None
-
JDK version and platform:1.6.0_23 for Windows
Description
This is the class to be serialized with XStream:
import com.thoughtworks.xstream.annotations.XStreamOmitField;
public class XStreamTestObject
{ int shouldNotBeOmitted = 1; @XStreamOmitField int shouldBeOmitted = 2; }The @XStreamOmitField has no effect. Using XStream.omitField() does the job as required. This is the class that calls the serialization
import com.thoughtworks.xstream.XStream;
public class XStreamTestMain {
public static void main(String[] args)
{ XStream xs = new XStream(); System.out.println("using annotation-------------------------"); System.out.println(xs.toXML(new XStreamTestObject())); xs.omitField(XStreamTestObject.class, "shouldBeOmitted"); System.out.println("using omitField()------------------------"); System.out.println(xs.toXML(new XStreamTestObject())); }}
And this is the output:
using annotation-------------------------
<XStreamTestObject>
<shouldNotBeOmitted>1</shouldNotBeOmitted>
<shouldBeOmitted>2</shouldBeOmitted>
</XStreamTestObject>
using omitField()------------------------
<XStreamTestObject>
<shouldNotBeOmitted>1</shouldNotBeOmitted>
</XStreamTestObject>
Unfortunately my line feeds have been removed in my example code. I'm going to attach it as Java files.