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 * Optional rank for this config. 039 * 040 * <p> 041 * Can be used to override default ordering and application of config annotations. 042 */ 043 int rank() default 0; 044 045 //------------------------------------------------------------------------------------------------------------------- 046 // JsonCommon 047 //------------------------------------------------------------------------------------------------------------------- 048 049 /** 050 * Dynamically applies {@link Json @Json} annotations to specified classes. 051 * 052 * <p> 053 * Provides an alternate approach for applying annotations using {@link Json#on() @Json.on} to specify the names 054 * to apply the annotation to. 055 * 056 * <ul class='seealso'> 057 * <li class='link'>{@doc juneau-marshall.DynamicallyAppliedAnnotations} 058 * </ul> 059 */ 060 Json[] applyJson() default {}; 061 062 //------------------------------------------------------------------------------------------------------------------- 063 // JsonParser 064 //------------------------------------------------------------------------------------------------------------------- 065 066 /** 067 * Configuration property: Validate end. 068 * 069 * <p> 070 * If <js>"true"</js>, after parsing a POJO from the input, verifies that the remaining input in 071 * the stream consists of only comments or whitespace. 072 * 073 * <ul class='notes'> 074 * <li> 075 * Possible values: 076 * <ul> 077 * <li><js>"true"</js> 078 * <li><js>"false"</js> (default) 079 * </ul> 080 * <li> 081 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 082 * </ul> 083 * 084 * <ul class='seealso'> 085 * <li class='jf'>{@link JsonParser#JSON_validateEnd} 086 * </ul> 087 */ 088 String validateEnd() default ""; 089 090 //------------------------------------------------------------------------------------------------------------------- 091 // JsonSerializer 092 //------------------------------------------------------------------------------------------------------------------- 093 094 /** 095 * Configuration property: Add <js>"_type"</js> properties when needed. 096 * 097 * <p> 098 * If <js>"true"</js>, then <js>"_type"</js> properties will be added to beans if their type cannot be inferred 099 * through reflection. 100 * 101 * <p> 102 * When present, this value overrides the {@link Serializer#SERIALIZER_addBeanTypes} setting and is 103 * provided to customize the behavior of specific serializers in a {@link SerializerGroup}. 104 * 105 * <ul class='notes'> 106 * <li> 107 * Possible values: 108 * <ul> 109 * <li><js>"true"</js> 110 * <li><js>"false"</js> (default) 111 * </ul> 112 * <li> 113 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 114 * </ul> 115 * 116 * <ul class='seealso'> 117 * <li class='jf'>{@link JsonSerializer#JSON_addBeanTypes} 118 * </ul> 119 */ 120 String addBeanTypes() default ""; 121 122 /** 123 * Configuration property: Prefix solidus <js>'/'</js> characters with escapes. 124 * 125 * <p> 126 * If <js>"true"</js>, solidus (e.g. slash) characters should be escaped. 127 * The JSON specification allows for either format. 128 * <br>However, if you're embedding JSON in an HTML script tag, this setting prevents confusion when trying to serialize 129 * <xt><\/script></xt>. 130 * 131 * <ul class='notes'> 132 * <li> 133 * Possible values: 134 * <ul> 135 * <li><js>"true"</js> 136 * <li><js>"false"</js> (default) 137 * </ul> 138 * <li> 139 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 140 * </ul> 141 * 142 * <ul class='seealso'> 143 * <li class='jf'>{@link JsonSerializer#JSON_escapeSolidus} 144 * </ul> 145 */ 146 String escapeSolidus() default ""; 147 148 /** 149 * Configuration property: Simple JSON mode. 150 * 151 * <p> 152 * If <js>"true"</js>, JSON attribute names will only be quoted when necessary. 153 * <br>Otherwise, they are always quoted. 154 * 155 * <p> 156 * Attributes do not need to be quoted when they conform to the following: 157 * <ol class='spaced-list'> 158 * <li>They start with an ASCII character or <js>'_'</js>. 159 * <li>They contain only ASCII characters or numbers or <js>'_'</js>. 160 * <li>They are not one of the following reserved words: 161 * <p class='bcode w800'> 162 * arguments, break, case, catch, class, const, continue, debugger, default, 163 * delete, do, else, enum, eval, export, extends, false, finally, for, function, 164 * if, implements, import, in, instanceof, interface, let, new, null, package, 165 * private, protected, public, return, static, super, switch, this, throw, 166 * true, try, typeof, var, void, while, with, undefined, yield 167 * </p> 168 * </ol> 169 * 170 * <ul class='notes'> 171 * <li> 172 * Possible values: 173 * <ul> 174 * <li><js>"true"</js> 175 * <li><js>"false"</js> (default) 176 * </ul> 177 * <li> 178 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 179 * </ul> 180 * 181 * <ul class='seealso'> 182 * <li class='jf'>{@link JsonSerializer#JSON_simpleMode} 183 * </ul> 184 */ 185 String simpleMode() default ""; 186}