001/*
002 * Default.java January 2010
003 *
004 * Copyright (C) 2010, Niall Gallagher <niallg@users.sf.net>
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
015 * implied. See the License for the specific language governing 
016 * permissions and limitations under the License.
017 */
018
019package org.simpleframework.xml;
020
021import java.lang.annotation.Retention;
022import java.lang.annotation.RetentionPolicy;
023
024/**
025 * The <code>Default</code> annotation is used to specify that all
026 * fields or methods should be serialized in a default manner. This
027 * basically allows an objects fields or properties to be serialized
028 * without the need to annotate them. This has advantages if the
029 * format of the serialized object is not important, as it allows
030 * the object to be serialized with a minimal use of annotations.
031 * <pre>
032 * 
033 *    &#64;Root
034 *    &#64;Default(DefaultType.FIELD)
035 *    public class Example {
036 *       ...
037 *    }
038 * 
039 * </pre>
040 * Defaults can be applied to either fields or property methods. If
041 * this annotation is applied to a class, certain fields or methods
042 * can be ignored using the <code>Transient</code> annotation. If a
043 * member is marked as transient then it will not be serialized. The
044 * defaults are applied only to those members that are not otherwise
045 * annotated with an XML annotation.
046 * 
047 * @author Niall Gallagher
048 * 
049 * @see org.simpleframework.xml.Transient
050 */
051@Retention(RetentionPolicy.RUNTIME)
052public @interface Default {
053   
054   /**
055    * This method is used to return the type of default that is to
056    * be applied to the class. Defaults can be applied to either
057    * fields or property methods. Any member with an XML annotation
058    * will not be treated as a default. 
059    * 
060    * @return this returns the type of defaults to be applied
061    */
062   DefaultType value() default DefaultType.FIELD;
063   
064   /**
065    * This is used to determine if the generated annotations are
066    * required or not. By default generated parameters are required.
067    * Setting this to false means that null values are accepted
068    * by all defaulted fields or methods depending on the type.
069    * 
070    * @return this is used to determine if defaults are required
071    */
072   boolean required() default true;
073}