001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.json.annotation;
014
015import static java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.*;
017
018import java.lang.annotation.*;
019
020import org.apache.juneau.annotation.*;
021import org.apache.juneau.json.*;
022import org.apache.juneau.serializer.*;
023
024/**
025 * Annotation for specifying config properties defined in {@link JsonSerializer} and {@link JsonParser}.
026 *
027 * <p>
028 * Used primarily for specifying bean configuration properties on REST classes and methods.
029 */
030@Documented
031@Target({TYPE,METHOD})
032@Retention(RUNTIME)
033@Inherited
034@PropertyStoreApply(JsonConfigApply.class)
035public @interface JsonConfig {
036
037   //-------------------------------------------------------------------------------------------------------------------
038   // JsonParser
039   //-------------------------------------------------------------------------------------------------------------------
040
041   /**
042    * Configuration property:  Validate end.
043    *
044    * <p>
045    * If <js>"true"</js>, after parsing a POJO from the input, verifies that the remaining input in
046    * the stream consists of only comments or whitespace.
047    *
048    * <ul class='notes'>
049    *    <li>
050    *       Possible values:
051    *       <ul>
052    *          <li><js>"true"</js>
053    *          <li><js>"false"</js> (default)
054    *       </ul>
055    *    <li>
056    *       Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>).
057    *    <li>
058    *       A default global value can be set via the system property <js>"JsonParser.validateEnd.b"</js>.
059    * </ul>
060    *
061    * <ul class='seealso'>
062    *    <li class='jf'>{@link JsonParser#JSON_validateEnd}
063    * </ul>
064    */
065   String validateEnd() default "";
066
067   //-------------------------------------------------------------------------------------------------------------------
068   // JsonSerializer
069   //-------------------------------------------------------------------------------------------------------------------
070
071   /**
072    * Configuration property:  Add <js>"_type"</js> properties when needed.
073    *
074    * <p>
075    * If <js>"true"</js>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred
076    * through reflection.
077    *
078    * <p>
079    * When present, this value overrides the {@link Serializer#SERIALIZER_addBeanTypes} setting and is
080    * provided to customize the behavior of specific serializers in a {@link SerializerGroup}.
081    *
082    * <ul class='notes'>
083    *    <li>
084    *       Possible values:
085    *       <ul>
086    *          <li><js>"true"</js>
087    *          <li><js>"false"</js> (default)
088    *       </ul>
089    *    <li>
090    *       Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>).
091    *    <li>
092    *       A default global value can be set via the system property <js>"JsonSerializer.addBeanTypes.b"</js>.
093    * </ul>
094    *
095    * <ul class='seealso'>
096    *    <li class='jf'>{@link JsonSerializer#JSON_addBeanTypes}
097    * </ul>
098    */
099   String addBeanTypes() default "";
100
101   /**
102    * Configuration property:  Prefix solidus <js>'/'</js> characters with escapes.
103    *
104    * <p>
105    * If <js>"true"</js>, solidus (e.g. slash) characters should be escaped.
106    * The JSON specification allows for either format.
107    * <br>However, if you're embedding JSON in an HTML script tag, this setting prevents confusion when trying to serialize
108    * <xt>&lt;\/script&gt;</xt>.
109    *
110    * <ul class='notes'>
111    *    <li>
112    *       Possible values:
113    *       <ul>
114    *          <li><js>"true"</js>
115    *          <li><js>"false"</js> (default)
116    *       </ul>
117    *    <li>
118    *       Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>).
119    *    <li>
120    *       A default global value can be set via the system property <js>"JsonSerializer.escapeSolidus.b"</js>.
121    * </ul>
122    *
123    * <ul class='seealso'>
124    *    <li class='jf'>{@link JsonSerializer#JSON_escapeSolidus}
125    * </ul>
126    */
127   String escapeSolidus() default "";
128
129   /**
130    * Configuration property:  Simple JSON mode.
131    *
132    * <p>
133    * If <js>"true"</js>, JSON attribute names will only be quoted when necessary.
134    * <br>Otherwise, they are always quoted.
135    *
136    * <p>
137    * Attributes do not need to be quoted when they conform to the following:
138    * <ol class='spaced-list'>
139    *    <li>They start with an ASCII character or <js>'_'</js>.
140    *    <li>They contain only ASCII characters or numbers or <js>'_'</js>.
141    *    <li>They are not one of the following reserved words:
142    *       <p class='bcode w800'>
143    *    arguments, break, case, catch, class, const, continue, debugger, default,
144    *    delete, do, else, enum, eval, export, extends, false, finally, for, function,
145    *    if, implements, import, in, instanceof, interface, let, new, null, package,
146    *    private, protected, public, return, static, super, switch, this, throw,
147    *    true, try, typeof, var, void, while, with, undefined, yield
148    *       </p>
149    * </ol>
150    *
151    * <ul class='notes'>
152    *    <li>
153    *       Possible values:
154    *       <ul>
155    *          <li><js>"true"</js>
156    *          <li><js>"false"</js> (default)
157    *       </ul>
158    *    <li>
159    *       Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>).
160    *    <li>
161    *       A default global value can be set via the system property <js>"JsonSerializer.simpleMode.b"</js>.
162    * </ul>
163    *
164    * <ul class='seealso'>
165    *    <li class='jf'>{@link JsonSerializer#JSON_simpleMode}
166    * </ul>
167    */
168   String simpleMode() default "";
169}