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