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.json.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.json.*;
026import org.apache.juneau.serializer.*;
027
028/**
029 * Annotation for specifying config properties defined in {@link JsonSerializer} and {@link JsonParser}.
030 *
031 * <p>
032 * Used primarily for specifying bean configuration properties on REST classes and methods.
033 *
034 * <h5 class='section'>See Also:</h5><ul>
035 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JsonBasics">JSON Basics</a>
036 * </ul>
037 */
038@Target({ TYPE, METHOD })
039@Retention(RUNTIME)
040@Inherited
041@ContextApply({ JsonConfigAnnotation.SerializerApply.class, JsonConfigAnnotation.ParserApply.class })
042public @interface JsonConfig {
043
044   /**
045    * Add <js>"_type"</js> properties when needed.
046    *
047    * <p>
048    * If <js>"true"</js>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred
049    * through reflection.
050    *
051    * <p>
052    * When present, this value overrides the {@link org.apache.juneau.serializer.Serializer.Builder#addBeanTypes()} setting and is
053    * provided to customize the behavior of specific serializers in a {@link SerializerSet}.
054    *
055    * <ul class='values'>
056    *    <li><js>"true"</js>
057    *    <li><js>"false"</js> (default)
058    * </ul>
059    *
060    * <h5 class='section'>Notes:</h5><ul>
061    *    <li class='note'>
062    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
063    * </ul>
064    *
065    * <h5 class='section'>See Also:</h5><ul>
066    *    <li class='jm'>{@link org.apache.juneau.json.JsonSerializer.Builder#addBeanTypesJson()}
067    * </ul>
068    *
069    * @return The annotation value.
070    */
071   String addBeanTypes() default "";
072
073   /**
074    * Prefix solidus <js>'/'</js> characters with escapes.
075    *
076    * <p>
077    * If <js>"true"</js>, solidus (e.g. slash) characters should be escaped.
078    * The JSON specification allows for either format.
079    * <br>However, if you're embedding JSON in an HTML script tag, this setting prevents confusion when trying to serialize
080    * <xt>&lt;\/script&gt;</xt>.
081    *
082    * <ul class='values'>
083    *    <li><js>"true"</js>
084    *    <li><js>"false"</js> (default)
085    * </ul>
086    *
087    * <h5 class='section'>Notes:</h5><ul>
088    *    <li class='note'>
089    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
090    * </ul>
091    *
092    * <h5 class='section'>See Also:</h5><ul>
093    *    <li class='jm'>{@link org.apache.juneau.json.JsonSerializer.Builder#escapeSolidus()}
094    * </ul>
095    *
096    * @return The annotation value.
097    */
098   String escapeSolidus() default "";
099
100   /**
101    * Optional rank for this config.
102    *
103    * <p>
104    * Can be used to override default ordering and application of config annotations.
105    *
106    * @return The annotation value.
107    */
108   int rank() default 0;
109
110   /**
111    * Simple JSON attribute mode.
112    *
113    * <p>
114    * If <js>"true"</js>, JSON attribute names will only be quoted when necessary.
115    * <br>Otherwise, they are always quoted.
116    *
117    * <p>
118    * Attributes do not need to be quoted when they conform to the following:
119    * <ol class='spaced-list'>
120    *    <li>They start with an ASCII character or <js>'_'</js>.
121    *    <li>They contain only ASCII characters or numbers or <js>'_'</js>.
122    *    <li>They are not one of the following reserved words:
123    *       <p class='bcode'>
124    *    arguments, break, case, catch, class, const, continue, debugger, default,
125    *    delete, do, else, enum, eval, export, extends, false, finally, for, function,
126    *    if, implements, import, in, instanceof, interface, let, new, null, package,
127    *    private, protected, public, return, static, super, switch, this, throw,
128    *    true, try, typeof, var, void, while, with, undefined, yield
129    *       </p>
130    * </ol>
131    *
132    * <ul class='values'>
133    *    <li><js>"true"</js>
134    *    <li><js>"false"</js> (default)
135    * </ul>
136    *
137    * <h5 class='section'>Notes:</h5><ul>
138    *    <li class='note'>
139    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
140    * </ul>
141    *
142    * <h5 class='section'>See Also:</h5><ul>
143    *    <li class='jm'>{@link org.apache.juneau.json.JsonSerializer.Builder#simpleAttrs()}
144    * </ul>
145    *
146    * @return The annotation value.
147    */
148   String simpleAttrs() default "";
149
150   /**
151    * Validate end.
152    *
153    * <p>
154    * If <js>"true"</js>, after parsing a POJO from the input, verifies that the remaining input in
155    * the stream consists of only comments or whitespace.
156    *
157    * <ul class='values'>
158    *    <li><js>"true"</js>
159    *    <li><js>"false"</js> (default)
160    * </ul>
161    *
162    * <h5 class='section'>Notes:</h5><ul>
163    *    <li class='note'>
164    *       Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>).
165    * </ul>
166    *
167    * <h5 class='section'>See Also:</h5><ul>
168    *    <li class='jm'>{@link org.apache.juneau.json.JsonParser.Builder#validateEnd()}
169    * </ul>
170    *
171    * @return The annotation value.
172    */
173   String validateEnd() default "";
174}