Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 49949 invoked from network); 26 Jan 2006 20:25:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 26 Jan 2006 20:25:38 -0000 Received: (qmail 47242 invoked by uid 500); 26 Jan 2006 20:25:32 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 47180 invoked by uid 500); 26 Jan 2006 20:25:32 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 47169 invoked by uid 99); 26 Jan 2006 20:25:32 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Jan 2006 12:25:30 -0800 Received: from ajax.apache.org (ajax.apache.org [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id 3C96BC9 for ; Thu, 26 Jan 2006 21:25:09 +0100 (CET) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Apache Wiki To: commons-dev@jakarta.apache.org Date: Thu, 26 Jan 2006 20:25:09 -0000 Message-ID: <20060126202509.22699.84798@ajax.apache.org> Subject: [Jakarta-commons Wiki] Update of "Betwixt/CustomPropertySuppressionStrategyExampleUsingJava5Annotations" by AlexVassiliev X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Dear Wiki user, You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification. The following page has been changed by AlexVassiliev: http://wiki.apache.org/jakarta-commons/Betwixt/CustomPropertySuppressionStrategyExampleUsingJava5Annotations New page: = 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 { private String name; @Persistent public String getName() { return name; } public void setName(String name) { this.name = name; } } }}} ===== 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() { @Override public boolean suppressProperty(Class classContainingTheProperty, Class propertyType, String propertyName) { boolean res = true; PropertyDescriptor[] pds; try { pds = Introspector.getBeanInfo(classContainingTheProperty).getPropertyDescriptors(); } catch (IntrospectionException e) { throw new Error(e); } for (int i = 0; i < pds.length; i++) { if (pds[i].getName().equals(propertyName) && pds[i].getReadMethod().isAnnotationPresent(Persistent.class)) { res = false; break; } } return res; } }); }}} --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org