001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.urlencoding.annotation;
018
019import static java.lang.annotation.ElementType.*;
020import static java.lang.annotation.RetentionPolicy.*;
021
022import java.lang.annotation.*;
023
024import org.apache.juneau.annotation.*;
025import org.apache.juneau.urlencoding.*;
026
027/**
028 * Annotation that can be applied to classes, fields, and methods to tweak how they are handled by
029 * {@link UrlEncodingSerializer} and {@link UrlEncodingParser}.
030 *
031 * <p>
032 * Can be used in the following locations:
033 * <ul>
034 *    <li>Marshalled classes/methods/fields.
035 *    <li><ja>@Rest</ja>-annotated classes and <ja>@RestOp</ja>-annotated methods when an {@link #on()} value is specified.
036 * </ul>
037 *
038 * <h5 class='section'>See Also:</h5><ul>
039 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/UrlEncodingBasics">URL-Encoding Basics</a>
040
041 * </ul>
042 */
043@Documented
044@Target({TYPE,FIELD,METHOD})
045@Retention(RUNTIME)
046@Inherited
047@Repeatable(UrlEncodingAnnotation.Array.class)
048@ContextApply(UrlEncodingAnnotation.Apply.class)
049public @interface UrlEncoding {
050
051    /**
052     * Optional description for the exposed API.
053     *
054     * @return The annotation value.
055     * @since 9.2.0
056     */
057    String[] description() default {};
058
059    /**
060    * When true, bean properties of type array or Collection will be expanded into multiple key/value pairings.
061    *
062    * <p>
063    * This annotation is identical in behavior to using the {@link org.apache.juneau.urlencoding.UrlEncodingSerializer.Builder#expandedParams()}
064    * and {@link org.apache.juneau.urlencoding.UrlEncodingParser.Builder#expandedParams()} properties, but applies to only instances of this bean.
065    *
066    * @return The annotation value.
067    */
068   boolean expandedParams() default false;
069
070   /**
071    * Dynamically apply this annotation to the specified classes/methods/fields.
072    *
073    * <p>
074    * Used in conjunction with {@link org.apache.juneau.BeanContext.Builder#applyAnnotations(Class...)} to dynamically apply an annotation to an existing class/method/field.
075    * It is ignored when the annotation is applied directly to classes/methods/fields.
076    *
077    * <h5 class='section'>Valid patterns:</h5>
078    * <ul class='spaced-list'>
079    *  <li>Classes:
080    *       <ul>
081    *          <li>Fully qualified:
082    *             <ul>
083    *                <li><js>"com.foo.MyClass"</js>
084    *             </ul>
085    *          <li>Fully qualified inner class:
086    *             <ul>
087    *                <li><js>"com.foo.MyClass$Inner1$Inner2"</js>
088    *             </ul>
089    *          <li>Simple:
090    *             <ul>
091    *                <li><js>"MyClass"</js>
092    *             </ul>
093    *          <li>Simple inner:
094    *             <ul>
095    *                <li><js>"MyClass$Inner1$Inner2"</js>
096    *                <li><js>"Inner1$Inner2"</js>
097    *                <li><js>"Inner2"</js>
098    *             </ul>
099    *       </ul>
100    *    <li>Methods:
101    *       <ul>
102    *          <li>Fully qualified with args:
103    *             <ul>
104    *                <li><js>"com.foo.MyClass.myMethod(String,int)"</js>
105    *                <li><js>"com.foo.MyClass.myMethod(java.lang.String,int)"</js>
106    *                <li><js>"com.foo.MyClass.myMethod()"</js>
107    *             </ul>
108    *          <li>Fully qualified:
109    *             <ul>
110    *                <li><js>"com.foo.MyClass.myMethod"</js>
111    *             </ul>
112    *          <li>Simple with args:
113    *             <ul>
114    *                <li><js>"MyClass.myMethod(String,int)"</js>
115    *                <li><js>"MyClass.myMethod(java.lang.String,int)"</js>
116    *                <li><js>"MyClass.myMethod()"</js>
117    *             </ul>
118    *          <li>Simple:
119    *             <ul>
120    *                <li><js>"MyClass.myMethod"</js>
121    *             </ul>
122    *          <li>Simple inner class:
123    *             <ul>
124    *                <li><js>"MyClass$Inner1$Inner2.myMethod"</js>
125    *                <li><js>"Inner1$Inner2.myMethod"</js>
126    *                <li><js>"Inner2.myMethod"</js>
127    *             </ul>
128    *       </ul>
129    *    <li>Fields:
130    *       <ul>
131    *          <li>Fully qualified:
132    *             <ul>
133    *                <li><js>"com.foo.MyClass.myField"</js>
134    *             </ul>
135    *          <li>Simple:
136    *             <ul>
137    *                <li><js>"MyClass.myField"</js>
138    *             </ul>
139    *          <li>Simple inner class:
140    *             <ul>
141    *                <li><js>"MyClass$Inner1$Inner2.myField"</js>
142    *                <li><js>"Inner1$Inner2.myField"</js>
143    *                <li><js>"Inner2.myField"</js>
144    *             </ul>
145    *       </ul>
146    *    <li>A comma-delimited list of anything on this list.
147    * </ul>
148    *
149    * <h5 class='section'>See Also:</h5><ul>
150    *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
151    * </ul>
152    *
153    * @return The annotation value.
154    */
155   String[] on() default {};
156
157   /**
158    * Dynamically apply this annotation to the specified classes.
159    *
160    * <p>
161    * Identical to {@link #on()} except allows you to specify class objects instead of a strings.
162    *
163    * <h5 class='section'>See Also:</h5><ul>
164    *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
165    * </ul>
166    *
167    * @return The annotation value.
168    */
169   Class<?>[] onClass() default {};
170}