Index: /Users/chungonn/development/projects/Xstream-trunk/src/test/com/thoughtworks/acceptance/annotations/AnnotationOmitFieldTest.java =================================================================== --- /Users/chungonn/development/projects/Xstream-trunk/src/test/com/thoughtworks/acceptance/annotations/AnnotationOmitFieldTest.java (revision 0) +++ /Users/chungonn/development/projects/Xstream-trunk/src/test/com/thoughtworks/acceptance/annotations/AnnotationOmitFieldTest.java (revision 0) @@ -0,0 +1,42 @@ + package com.thoughtworks.acceptance.annotations; + +import com.thoughtworks.acceptance.AbstractAcceptanceTest; +import com.thoughtworks.xstream.annotations.Annotations; +import com.thoughtworks.xstream.annotations.XStreamAlias; +import com.thoughtworks.xstream.annotations.XStreamOmitField; + +/** + * Simple tests for OmitField annotations + * + * @author Chung-Onn Cheong + * + */ +public class AnnotationOmitFieldTest extends AbstractAcceptanceTest { + + public static class House { + + @XStreamOmitField + int size; + + @XStreamAlias("total-number-of-rooms") + private int rooms; + protected House(int rooms) { + this.rooms = rooms; + } + + public int getRooms() { + return rooms; + } + } + + public void testOmitFieldAnnotation() { + Annotations.configureAliases(xstream, House.class); + House house = new House(5); + String expectedXml = + "\n"+ + " 5\n" + + ""; + + assertBothWays(house, expectedXml); + } +} Index: /Users/chungonn/development/projects/Xstream-trunk/src/java/com/thoughtworks/xstream/annotations/XStreamOmitField.java =================================================================== --- /Users/chungonn/development/projects/Xstream-trunk/src/java/com/thoughtworks/xstream/annotations/XStreamOmitField.java (revision 0) +++ /Users/chungonn/development/projects/Xstream-trunk/src/java/com/thoughtworks/xstream/annotations/XStreamOmitField.java (revision 0) @@ -0,0 +1,21 @@ +package com.thoughtworks.xstream.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * An annotation for marking a field as an implicit collection. + * + * @author Chung-Onn Cheong + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface XStreamOmitField { + /** + * Field to be omitted + */ + String itemFieldName() default ""; +} Index: /Users/chungonn/development/projects/Xstream-trunk/src/java/com/thoughtworks/xstream/annotations/Annotations.java =================================================================== --- /Users/chungonn/development/projects/Xstream-trunk/src/java/com/thoughtworks/xstream/annotations/Annotations.java (revision 1125) +++ /Users/chungonn/development/projects/Xstream-trunk/src/java/com/thoughtworks/xstream/annotations/Annotations.java (working copy) @@ -161,6 +161,12 @@ xstream.addImplicitCollection(configurableClass, fieldName, itemType); } } + + //Do field level OmitField + if (field.isAnnotationPresent(XStreamOmitField.class)){ + String fieldName = field.getName(); + xstream.omitField(configurableClass, fieldName); + } } //Do Member Classes Alias