Customizing PropertySuppressionStrategy to use Java 5 Annotations

Suppose we want to mark properties to be serialized with Java 5 @Persistent annotation. So our bean code will look somewhat like this:

{{{public class Person {

} }}}

Here is one way of doing that

First define annotation: {{{@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public static @interface Persistent { } }}}

Then replace the default PropertySuppressionStrategy with our custom one: {{{beanWriter.getXMLIntrospector().getConfiguration().setPropertySuppressionStrategy(new PropertySuppressionStrategy() {

}); }}}

Betwixt/CustomPropertySuppressionStrategyExampleUsingJava5Annotations (last edited 2009-09-20 23:48:28 by localhost)