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